19.4.28
setVelocityFunc
self = physics.Body:setVelocityFunc(func)
Parameter |
Type |
Description |
---|---|---|
self |
in physics.Body |
The input Body |
func |
in function(body, grav, damping, dt) |
A callback function that updates the ve- locity of the Body on each time step |
self |
out physics.Body |
The input Body is returned as the output |
Sets the velocity function of the body. The velocity function must be a function that accepts a Body, a gravity vector, a numeric damping factor, and a time step value. The function should call body:updateVelocity to adjust the velocity of the body.
Returns the Body.
Listing 19.2: Example for physics.Body:setVelocityFunc()
functionsampleVelocityFunc(body, gravity, damping, dt)
local pos = body:pos()
local sqdist = pos:lengthsq()
local g = pos:mult(-GravityStrength /
(sqdist * math.sqrt(sqdist)))
body:updateVelocity(g, damping, dt)
end
body:setVelocityFunc(sampleVelocityFunc)
Introduced in platform.apiLevel = '2.0'