feat: add state machine movement classes, double barrel shotgun weapon, and test level builder utility

This commit is contained in:
DottsGit
2026-06-04 01:21:50 -04:00
parent a54b3d89b1
commit 45fb7f0f38
6 changed files with 177 additions and 42 deletions
+14 -11
View File
@@ -31,20 +31,23 @@ func update(delta: float) -> void:
# ── Air control ───────────────────────────────────────────────────────
var wish_dir: Vector3 = machine.wish_dir_world
var hvel := Vector3(vel.x, 0.0, vel.z)
var current_speed := hvel.length()
if wish_dir.length_squared() > 0.01:
var target_speed := maxf(current_speed, params.walk_speed)
target_speed = minf(target_speed, params.max_air_speed)
wish_dir = wish_dir.normalized()
var current_speed = hvel.length()
var target_vel := wish_dir * target_speed
var new_hvel = hvel.lerp(target_vel, 1.0 - exp(-params.air_control * params.air_acceleration * delta))
# Add a strong force in the wish direction
var air_accel = params.air_strafe_accel * delta
var new_hvel = hvel + wish_dir * air_accel
# Prevent speed loss during sharp turns, but allow braking if holding backward
if hvel.dot(target_vel) >= 0.0 and current_speed > params.walk_speed:
if new_hvel.length_squared() > 0.01:
new_hvel = new_hvel.normalized() * current_speed
# Limit the speed so we don't gain speed purely from air control.
# We only allow air control to change our direction (strafing)
# or to accelerate us up to our walk speed if we started slow.
var max_allowed_speed = maxf(current_speed, params.walk_speed)
if new_hvel.length() > max_allowed_speed:
new_hvel = new_hvel.normalized() * max_allowed_speed
hvel = new_hvel
else:
# No input: slight air drag (very subtle)
@@ -64,7 +67,7 @@ func update(delta: float) -> void:
# Bunny hop: if jump was buffered or pressed on landing frame
if machine.input_jump_pressed or machine.jump_buffer_time > 0.0:
var land_speed := Vector3(player.velocity.x, 0.0, player.velocity.z).length()
var bhop_speed := minf(land_speed + params.bunny_hop_speed_gain, params.bunny_hop_speed_cap)
var bhop_speed := maxf(land_speed, minf(land_speed + params.bunny_hop_speed_gain, params.bunny_hop_speed_cap))
# Maintain horizontal direction, boost speed
var hdir := Vector3(player.velocity.x, 0.0, player.velocity.z)
if hdir.length_squared() > 0.01: