Type Function Object Body Library physics.* Return value none Revision 2019.3470 Keywords body, applyForce See also object:applyLinearImpulse() object:applyTorque() object:applyAngularImpulse()
A function that accepts x and y components of a linear force, applied at a given point with x and y world coordinates. If the target point is the body's center of mass, it will tend to push the body in a straight line; if the target is offset from the body's center of mass, the body will spin about its center of mass.
Note that the amount of force required to move heavy objects may need to be fairly high.
object:applyForce( xForce, yForce, bodyX, bodyY )
Numbers. Amount of force to apply in the x and y directions respectively.
Numbers. Point on the object to apply the force to.
-- Create a rectangle local myRect = display.newRect( 0, 0, 100, 100 ) -- Add a body to the rectangle physics.addBody( myRect, "dynamic" ) -- Apply force myRect:applyForce( 50, 200, myRect.x, myRect.y )