object:applyLinearImpulse()

Type Function
Object Body
Library physics.*
Return value none
Revision Release 2024.3703
Keywords body, applyLinearImpulse
See also object:applyForce()
object:setLinearVelocity()
object.linearDamping
object:applyAngularImpulse()

Overview

Similar to object:applyForce() except that an impulse is a single momentary jolt.

Syntax

object:applyLinearImpulse( xForce, yForce, bodyX, bodyY )
xForce, yForce (required)

Numbers. Amount of force to apply in the x and y directions respectively.

bodyX, bodyY (required)

Numbers. Point on the object to apply the force to.

Example

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

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

-- Apply linear impulse
myRect:applyLinearImpulse( 60, 20, myRect.x, myRect.y )