Skip to content

PhysicsUpdate

Callback ยท a function named PhysicsUpdate that a script defines and the engine calls

PhysicsUpdate(dt: number) -> ()

PhysicsUpdate is a global function that the engine calls before every physics step with the step length in seconds, for code that pushes parts with forces. Declare it before the script's first wait, as for Update.

On a client, PhysicsUpdate runs again for scripts on the player's own character when the client replays ticks to match the server.

Example

-- Server script in a dynamic part: cancel gravity so it floats.
if self.Body then
    self.Body.Motion = "Dynamic"
end

function PhysicsUpdate(dt: number)
    local body = self.Body
    if body then
        local mass = body.Mass or 0
        body:ApplyForce(-mass * World.Gravity)
    end
end