object:vibrate()

Type Function
Object InputDevice
Return value none
Revision 2017.3145
Keywords device, input, vibrate, canVibrate
See also object.canVibrate

Overview

Causes the input device to vibrate/rumble.

This is a feature that is typically only supported by gamepads. You can determine if the input device supports vibration feedback by reading its canVibrate property.

Gotchas

On Android, you must add the following permission to the build.settings file.

settings =
{
    android =
    {
        usesPermissions =
        {
            "android.permission.VIBRATE",
        },
    },
}

Example

-- Called when a key event has been received
local function onKeyEvent( event )
    -- Vibrate the gamepad if its 'A' button was pressed
    if ( event.keyName == "buttonA" ) and ( event.phase == "down" ) then
        if event.device and event.device.canVibrate then
            event.device:vibrate()
        end
    end
end

-- Set up the above function to receive key events
Runtime:addEventListener( "key", onKeyEvent )