object:getLinearVelocity()

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

Overview

A function that returns the x and y components for the body's linear velocity, in pixels per second.

Syntax

object:getLinearVelocity()

Example

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

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

-- Start moving the rectangle
myRect:setLinearVelocity( 50, 20 )

-- Get the linear velocity values
local vx, vy = myRect:getLinearVelocity()