game/src/net/walker.rs#
Source: lib/game/src/net/walker.rs
walker -- the netcode's reference movement: a kinematic capsule that walks, runs, jumps, falls and
slides along what it touches (like apps/gamedemo's walker, with gravity); deterministic and on the
grid, so a client predicts exactly what the server computes. G7h's character controller (lib/physics,
G7c part 2) takes its place behind the same trait (predict::Movement)
WalkState feet position and velocity on the grid of quant.rs (1/1024 m, 1/1024 m/s), flags (on the
ground) and the buttons of the tick before (for edges: a jump is a press, not a hold)
Walker the parameters (capsule, speeds, jump, gravity, air control); Movement::step
BTN_* the buttons the walker reads (and the arena's FIRE)
A step: on the ground the horizontal velocity is the wish (walk or run along the view's yaw), a jump
press lifts off; in the air the wish pulls the velocity a little (air control) and gravity pulls it
down. The capsule is cast through the map along the motion, up to four times: to the contact less a
millimetre, the rest projected onto the surface, the velocity into the surface taken away. Then a
short cast down decides "on the ground" (a surface steeper than about 45 degrees is a wall), and the
position and velocity are rounded onto the grid.
/// a button: jump (a press lifts off)
BTN_JUMP: u16 = 1
/// a button: run (held)
BTN_RUN: u16 = 2
/// a button: fire (the arena's hitscan)
BTN_FIRE: u16 = 4
/// the walker's state flag: standing on the ground
FLAG_GROUND: u32 = 1
struct WalkStatethe walker's movement state (see the module header)pos: [i32; 3]-- the feet (the bottom of the capsule), in 1/1024 mvel: [i32; 3]-- the velocity in 1/1024 m/sflags: u32-- FLAG_GROUND in bit 0, the buttons of the tick before in bits 16 ..= 31
impl WalkState
fn at(p: Vec3) -> WalkStatestanding at feet position p (metres) on the groundfn feet(&self) -> Vec3the feet in metresfn velocity(&self) -> Vec3the velocity in m/sfn grounded(&self) -> boolon the groundstruct Walkerthe walker's parameters (see the module header)half: f64-- the capsule's half height (of its straight part) and radiusradius: f64-- see halfwalk: f64-- walking and running speed (m/s)run: f64-- see walkjump: f64-- the upward speed of a jump (m/s)gravity: f64-- gravity (m/s^2)air: f64-- how fast the wish pulls the velocity in the air (1/s)max_fall: f64-- the fastest fall (m/s)ground_cos: f64-- the smallest normal.y of a surface to stand on (cos of the steepest slope)
impl Walker
fn shape(&self) -> Shapethe capsulefn centre(&self) -> Vec3the capsule's centre above the feetfn eye(&self) -> f64where the eye is above the feet