JFLib

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 WalkState the walker's movement state (see the module header)
    • pos: [i32; 3] -- the feet (the bottom of the capsule), in 1/1024 m
    • vel: [i32; 3] -- the velocity in 1/1024 m/s
    • flags: u32 -- FLAG_GROUND in bit 0, the buttons of the tick before in bits 16 ..= 31

impl WalkState

  • fn at(p: Vec3) -> WalkState standing at feet position p (metres) on the ground

  • fn feet(&self) -> Vec3 the feet in metres

  • fn velocity(&self) -> Vec3 the velocity in m/s

  • fn grounded(&self) -> bool on the ground

  • fn last_buttons(&self) -> u16 the buttons of the tick before

  • struct Walker the walker's parameters (see the module header)

    • half: f64 -- the capsule's half height (of its straight part) and radius
    • radius: f64 -- see half
    • walk: f64 -- walking and running speed (m/s)
    • run: f64 -- see walk
    • jump: 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) -> Shape the capsule
  • fn centre(&self) -> Vec3 the capsule's centre above the feet
  • fn eye(&self) -> f64 where the eye is above the feet

Source: docs/API.md in the JFLib repository.