object:setLinearVelocity()

Type Function
Object Body
Library physics.*
Return value none
Revision Release 2022.3683
Keywords body, setLinearVelocity
See also object:getLinearVelocity()

Overview

This function accepts x and y components for the body's linear velocity, in pixels per second.

Syntax

object:setLinearVelocity( xVelocity, yVelocity )
xVelocity, yVelocity (required)

Numbers. Value for the velocity in the x and y directions respectively.

Example

-- Create a rectangle
local myRect = display.newRect( 0, 0, 100, 100 )

-- Add a body to the rectangle
physics.addBody( myRect, "dynamic" )

-- Set the linear velocity
myRect:setLinearVelocity( 10, 4 )