Log inGet started
Package

physics.module

Newest version

This package holds more than this page lists. See all of its files in its world.

README.md

push

How a character moved by casts pushes the dynamic bodies it walks into. The wall pass stops the character at a body as at a wall; this gives the body the push a walker gives it. No state.

Exports

  • M.into(hit, walkX: number, walkZ: number, pushForce: number, dt: number, frame?) -> number — push the dynamic body the walk met (hit, a cast hit naming the collider's entity; Physics.bodyOf names the body it rides). Along the way into the surface the walk met, laid flat across the frame, the push brings the body's speed up to the part of the walk going into it and no further, with at most pushForce * dt newton-seconds, through the body's centre of mass, so a crate slides along rather than tipping. Returns the impulse given: 0 for a hit on no dynamic body, a walk that does not go into it, or a body already moving away at that speed.

The model

A body moves when the push is more than what holds it: on level ground a box of mass m sliding with friction coefficient mu needs mu * m * 9.81 newtons. At the CharacterController default of 400 N, a 5 kg crate (about 34 N with the default box friction) and a 40 kg one (about 275 N) are carried along at the walk, the heavier one taking longer to come up to speed, and a 500 kg one (about 3400 N) does not move: the character stands against it as against a wall.

Usage

local Push = require("@builtin::systems.characterController.characterController.physics.push")

local step = Walls.move(px, py, pz, vx * dt, vz * dt, 1.8, 0.3, 0.01, 45, selfId, frame)
if step.hit then Push.into(step.hit, vx, vz, 400, dt, frame) end