~/bend-docscommunity

physics.bend checks

raw source on the hub · import 0xc517d5d3635f5bc3ec47170caccaebf0/physics.bend as Physics

1 import
import Base

Types

type Vec3 source · line 8 · raw

Data

type Player source · line 29 · raw

Data

Definitions

def Vec3.zero source · line 11 · raw

Vec3

def Vec3.add source · line 14 · raw

@a:Vec3 -> @b:Vec3 -> Vec3

def Vec3.scale source · line 19 · raw

@+s:F32 -> @v:Vec3 -> Vec3

def Vec3.is_eq source · line 24 · raw

@a:Vec3 -> @b:Vec3 -> Bool

def Player.spawn source · line 32 · raw

Player

def Physics.gravity source · line 36 · raw

F32

Movement constants (defs returning F32, single source of truth).

def Physics.jump_vel source · line 39 · raw

F32

def Physics.walk_speed source · line 42 · raw

F32

def Physics.fly_speed source · line 45 · raw

F32

def Physics.terminal source · line 48 · raw

F32

def Physics.epsilon source · line 51 · raw

F32

def Physics.clamp_fall source · line 55 · raw

@vy:F32 -> F32

Clamp falling speed to terminal velocity.

def Physics.clamp_axis source · line 59 · raw

@v:F32 -> @lo:F32 -> @hi:F32 -> F32

Clamp one axis into [lo, hi].

def Physics.blocked source · line 64 · raw

@+block:U32 -> Bool

Solid check (duplicated small on purpose, no world import): blocked = not (b == air(0) or b == water(7)).

def Physics.any_blocked source · line 69 · raw

@solid:List<&1, U32> -> Bool

True if any block id in the nearby list is solid. Only recursive def over List here; solid is first and shrinks via tail.

def Physics.fall_vy source · line 78 · raw

@vy:F32 -> @dt:F32 -> @fly:Bool -> @on_ground:Bool -> F32

Vertical velocity after gravity over dt. Falls only when airborne and not flying; otherwise unchanged. Clamps to terminal.

def Physics.jump_vy source · line 90 · raw

@vy:F32 -> @on_ground:Bool -> @jump:Bool -> F32

Jump: grounded + pressed sets upward velocity, else keeps vy.

def Physics.fric_factor source · line 102 · raw

@dt:F32 -> @on_ground:Bool -> F32

Friction/drag factor over dt: strong on ground, mild in air.

def Physics.grounded_go source · line 110 · raw

@below:Bool -> @slow:Bool -> Bool

Grounded when there is support below and we are not moving up.

def Physics.shift_x source · line 122 · raw

@pos:Vec3 -> @delta:F32 -> Vec3

Single-axis pure shifts.

def Physics.shift_y source · line 127 · raw

@pos:Vec3 -> @delta:F32 -> Vec3

def Physics.shift_z source · line 132 · raw

@pos:Vec3 -> @delta:F32 -> Vec3

def Physics.shift_go source · line 138 · raw

@pos:Vec3 -> @delta:F32 -> @is_x:Bool -> @is_y:Bool -> Vec3

Dispatch a pure shift from precomputed axis flags (avoids matching on U32).

def Physics.aabb_overlap source · line 148 · raw

@a_min:Vec3 -> @a_max:Vec3 -> @b_min:Vec3 -> @b_max:Vec3 -> Bool

Pure AABB overlap test on min/max corners.

def Player.turn_go source · line 154 · raw

@pos:Vec3 -> @vel:Vec3 -> @yaw:F32 -> @pitch:F32 -> @og:Bool -> @fly:Bool -> @dx:F32 -> @dy:F32 -> Player

Look helpers (defined before their Player wrappers).

def Player.dir_go source · line 157 · raw

@+yaw:F32 -> @+pitch:F32 -> Vec3

def Player.eye_go source · line 160 · raw

@pos:Vec3 -> Vec3

def Physics.step_vel source · line 166 · raw

@v:Vec3 -> @on_ground:Bool -> @fly:Bool -> @dt:F32 -> Vec3

Pure physics velocity step: gravity when airborne and not flying.

def Physics.apply_gravity source · line 172 · raw

@vel:Vec3 -> @dt:F32 -> @fly:Bool -> Vec3

Gravity only (no ground check here; game.bend supplies fly mode).

def Physics.apply_jump source · line 178 · raw

@vel:Vec3 -> @on_ground:Bool -> @jump:Bool -> Vec3

Jump impulse when grounded and pressed.

def Physics.apply_friction source · line 184 · raw

@vel:Vec3 -> @on_ground:Bool -> @dt:F32 -> Vec3

Horizontal friction/drag; vertical untouched.

def Physics.step_pos source · line 194 · raw

@pos:Vec3 -> @vel:Vec3 -> @+dt:F32 -> Vec3

Semi-implicit Euler position step: pos + vel * dt.

def Physics.try_move source · line 200 · raw

@pos:Vec3 -> @dx:F32 -> @dy:F32 -> @dz:F32 -> Vec3

Pure add of a delta triple (game.bend does collision around this).

def Physics.is_on_ground source · line 206 · raw

@vy:F32 -> @below:Bool -> Bool

Grounded from vertical speed + support below (no world lookup here).

def Physics.shift_axis source · line 210 · raw

@pos:Vec3 -> @delta:F32 -> @+axis:U32 -> Vec3

Pure single-axis shift selected by axis id (0 = x, 1 = y, else z).

def Physics.collide_axis source · line 215 · raw

@pos:Vec3 -> @delta:F32 -> @+axis:U32 -> @hit:Bool -> Pair(Vec3, Bool)

Per-axis resolve from a precomputed hit flag: stay + True on hit, else shift + False. game.bend loops this with world lookups.

def Physics.move_axis source · line 223 · raw

@pos:Vec3 -> @delta:F32 -> @+axis:U32 -> @solid:List<&1, U32> -> Pair(Vec3, Bool)

Per-axis resolve from a small list of nearby block ids.

def Physics.collide source · line 227 · raw

@pos:Vec3 -> @new_pos:Vec3 -> @hit:Bool -> Pair(Vec3, Bool)

Pure collide between current and candidate positions.

def Physics.player_aabb_corners source · line 236 · raw

@+pos:Vec3 -> List<&1, Vec3>

8 AABB corners for a player at feet pos (half width 0.3, height 1.8). game.bend maps these through world lookups for collision.

def Player.turn source · line 242 · raw

@p:Player -> @+dx:F32 -> @+dy:F32 -> Player

Yaw/pitch look; dx/dy are mouse deltas scaled by sensitivity.

def Player.dir source · line 248 · raw

@p:Player -> Vec3

Forward vector from yaw/pitch.

def Player.eye source · line 254 · raw

@p:Player -> Vec3

Eye position (feet + 1.6 height).

def Physics.integrate_go source · line 262 · raw

@pos:Vec3 -> @vel:Vec3 -> @yaw:F32 -> @pitch:F32 -> @+og:Bool -> @+fly:Bool -> @+dt:F32 -> Player

Pure physics integrate (no input, no collision): gravity then move. Player.apply_input (wish dirs/jump) lives in the player module and runs before this; world/game collision runs after via try_move/collide_axis.

def Physics.integrate source · line 267 · raw

@p:Player -> @+dt:F32 -> Player

def Physics.law_gravity_holds source · line 273 · raw

@+vy:F32 -> @dt:F32 -> Bool

LAW: gravity never increases fall velocity (airborne, not flying).

def Physics.law_jump_holds source · line 277 · raw

Bool

LAW: jumping while grounded sets upward velocity to jump_vel.

def Physics.law_zero_dt_holds source · line 281 · raw

@+pos:Vec3 -> @vel:Vec3 -> Bool

LAW: zero dt does not move the player.

def Physics.sprint_speed source · line 286 · raw

F32

--- Sprint / sneak / swim / step / glide constants (additive) --- Sprint = Ctrl hold (walk 5.0 stays). Double-W not tracked; sprint is explicit.

def Physics.sneak_speed source · line 289 · raw

F32

def Physics.swim_speed source · line 292 · raw

F32

def Physics.step_height source · line 295 · raw

F32

def Physics.glide_rate source · line 298 · raw

F32

def Physics.glide_max source · line 301 · raw

F32

def Physics.air_drag source · line 304 · raw

F32

def Physics.fly_drag source · line 307 · raw

F32

def Physics.water_factor source · line 310 · raw

F32

def Physics.ice_friction source · line 313 · raw

F32

def Physics.ground_friction source · line 316 · raw

F32

def Physics.drown_max source · line 319 · raw

U32

def Physics.drown_ticks source · line 322 · raw

U32

def Physics.speed_of source · line 326 · raw

@sprint:Bool -> F32

Sprint selector: True -> sprint_speed, else walk_speed.

def Physics.water_drag source · line 334 · raw

@v:F32 -> F32

Water drag on one axis: scale by water factor.

def Physics.swim_lift source · line 338 · raw

@swim:Bool -> @in_water:Bool -> F32

Swim lift: upward velocity when swimming in water, else 0.

def Physics.can_step_go source · line 350 · raw

@le:Bool -> @gt:Bool -> Bool

Step-up helper + main: 0.0 < dy <= step_height.

def Physics.can_step source · line 353 · raw

@+dy:F32 -> Bool

def Physics.knockback source · line 357 · raw

@vx:F32 -> @vz:F32 -> @kx:F32 -> @kz:F32 -> Pair(F32, F32)

Knockback: add horizontal impulse (vx+kx, vz+kz).

def Physics.fall_damage_go source · line 363 · raw

@small:Bool -> @fall:F32 -> U32

Fall damage helper + main: 0 under 3.5, else (fall-3.5) rounded.

def Physics.fall_damage source · line 370 · raw

@+fall:F32 -> U32

def Physics.scale_vel source · line 374 · raw

@vel:Vec3 -> @+k:F32 -> Vec3

Fluid drag: uniform scale helper, then air/fly/water selectors.

def Physics.apply_air source · line 379 · raw

@vel:Vec3 -> Vec3

def Physics.apply_fly_drag source · line 382 · raw

@vel:Vec3 -> Vec3

def Physics.apply_water_vel source · line 385 · raw

@vel:Vec3 -> Vec3

def Physics.apply_fluid_air source · line 388 · raw

@vel:Vec3 -> @fly:Bool -> Vec3

def Physics.apply_fluid_water source · line 395 · raw

@vel:Vec3 -> @in_water:Bool -> @fly:Bool -> Vec3

def Physics.apply_fluid source · line 402 · raw

@vel:Vec3 -> @in_water:Bool -> @fly:Bool -> Vec3

def Physics.bump_go source · line 406 · raw

@blocked:Bool -> @up:Bool -> @vy:F32 -> F32

Head bump helper + main: zero upward vy on ceiling.

def Physics.bump source · line 417 · raw

@+vy:F32 -> @blocked_above:Bool -> F32

def Physics.glide_drop source · line 421 · raw

@fly_speed:F32 -> F32

Elytra-lite glide: sink rate from forward speed, clamped to max.

def Physics.friction_pick source · line 425 · raw

@is_ice:Bool -> F32

Slippery ice: block 12 (reserved ice, blocks.bend has 0-11) -> 0.98 else 0.7.

def Physics.friction_of source · line 432 · raw

@block:U32 -> F32