Feat/1 movement foundation #5
@@ -1,4 +1,46 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
|
||||
[*.gd]
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
max_line_length = 120
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.tscn]
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.tres]
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.md]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = true
|
||||
max_line_length = 120
|
||||
insert_final_newline = true
|
||||
|
||||
[*.cfg]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[.env*]
|
||||
charset = utf-8
|
||||
indent_style = unset
|
||||
trim_trailing_whitespace = false
|
||||
end_of_line = unset
|
||||
insert_final_newline = unset
|
||||
max_line_length = unset
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
extends Node3D
|
||||
class_name FPSCameraRig
|
||||
|
||||
## FPS camera rig — handles mouse look, head bob, FOV kick, wall-run tilt.
|
||||
## Attach as child of the CharacterBody3D player. Camera3D is a child of this node.
|
||||
|
||||
@export var sensitivity: float = 0.002
|
||||
@export var pitch_limit: float = 89.0
|
||||
|
||||
var params: MovementParams
|
||||
var camera: Camera3D
|
||||
var _bob_timer: float = 0.0
|
||||
var _target_tilt: float = 0.0
|
||||
var _current_tilt: float = 0.0
|
||||
var _target_fov: float = 90.0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
camera = get_node_or_null("Camera3D")
|
||||
if camera and params:
|
||||
camera.fov = params.base_fov
|
||||
_target_fov = params.base_fov
|
||||
# Explicitly enable callbacks — set_script() at runtime doesn't auto-register them
|
||||
set_process_input(true)
|
||||
set_process(true)
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
|
||||
var sens := sensitivity
|
||||
if params:
|
||||
sens = params.mouse_sensitivity
|
||||
# Yaw: rotate the player (parent)
|
||||
get_parent().rotate_y(-event.relative.x * sens)
|
||||
# Pitch: rotate this pivot
|
||||
rotation.x = clampf(rotation.x - event.relative.y * sens, deg_to_rad(-pitch_limit), deg_to_rad(pitch_limit))
|
||||
|
||||
# Toggle mouse capture with Escape
|
||||
if event is InputEventKey and event.pressed and event.keycode == KEY_ESCAPE:
|
||||
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
else:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if not camera or not params:
|
||||
return
|
||||
|
||||
var player: CharacterBody3D = get_parent() as CharacterBody3D
|
||||
if not player:
|
||||
return
|
||||
|
||||
# ── FOV kick ──────────────────────────────────────────────────────────
|
||||
_target_fov = params.base_fov
|
||||
var hspeed := Vector2(player.velocity.x, player.velocity.z).length()
|
||||
|
||||
# Dash FOV (highest priority)
|
||||
if hspeed > params.dash_speed * 0.8:
|
||||
_target_fov = params.dash_fov
|
||||
elif hspeed > params.sprint_speed * 0.8:
|
||||
_target_fov = params.sprint_fov
|
||||
|
||||
camera.fov = lerpf(camera.fov, _target_fov, 1.0 - exp(-params.fov_lerp_speed * delta))
|
||||
|
||||
# ── Head bob ──────────────────────────────────────────────────────────
|
||||
var sm = player.get_node_or_null("MovementStateMachine")
|
||||
var is_sliding = sm and sm.current_state == "slide"
|
||||
|
||||
if player.is_on_floor() and hspeed > 1.0 and not is_sliding:
|
||||
_bob_timer += delta * params.head_bob_frequency * (hspeed / params.walk_speed)
|
||||
var bob_y := sin(_bob_timer) * params.head_bob_amplitude
|
||||
var bob_x := cos(_bob_timer * 0.5) * params.head_bob_amplitude * 0.5
|
||||
camera.position.y = lerp(camera.position.y, bob_y, 0.3)
|
||||
camera.position.x = lerp(camera.position.x, bob_x, 0.3)
|
||||
else:
|
||||
_bob_timer = 0.0
|
||||
camera.position.y = lerp(camera.position.y, 0.0, 0.15)
|
||||
camera.position.x = lerp(camera.position.x, 0.0, 0.15)
|
||||
|
||||
# ── Wall-run tilt ─────────────────────────────────────────────────────
|
||||
_current_tilt = lerpf(_current_tilt, _target_tilt, 1.0 - exp(-params.wall_run_tilt_speed * delta))
|
||||
camera.rotation.z = deg_to_rad(_current_tilt)
|
||||
|
||||
|
||||
## Called by the movement system to set wall-run tilt direction.
|
||||
## side: -1.0 (left wall), 1.0 (right wall), 0.0 (no tilt)
|
||||
func set_wall_tilt(side: float) -> void:
|
||||
if params:
|
||||
_target_tilt = side * params.wall_run_tilt_angle
|
||||
else:
|
||||
_target_tilt = side * 12.0
|
||||
|
||||
|
||||
## Called to reset tilt (e.g., on landing).
|
||||
func clear_wall_tilt() -> void:
|
||||
_target_tilt = 0.0
|
||||
@@ -0,0 +1 @@
|
||||
uid://b1nbudf4cu2dl
|
||||
@@ -0,0 +1,17 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://player_base"]
|
||||
|
||||
[ext_resource type="Script" path="res://movement/player_movement_controller.gd" id="1"]
|
||||
|
||||
[node name="PlayerBase" type="CharacterBody3D"]
|
||||
|
||||
[node name="PlayerMovementController" type="Node" parent="."]
|
||||
script = ExtResource("1")
|
||||
|
||||
[node name="MovementStateMachine" type="Node" parent="PlayerMovementController"]
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="PlayerMovementController"]
|
||||
|
||||
[node name="CapsuleShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = CapsuleShape3D.new()
|
||||
shape.radius = 0.4
|
||||
shape.height = 1.8
|
||||
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bash
|
||||
# Papaya-Shooter test environment bootstrap
|
||||
# shell: bash
|
||||
# Repo root: /home/ai-agent/Papay-Shooter
|
||||
# Usage: bash debug_test_env.sh
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
REPO="/home/ai-agent/Papay-Shooter"
|
||||
ENV_FILE="$REPO/.env_test"
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
timestamp() { date '+%Y-%m-%d %H:%M:%S'; }
|
||||
log() { echo -e "[$(timestamp)] $*"; }
|
||||
|
||||
log "===Papaya-Shooter Test Environment Bootstrap==="
|
||||
log "Repo: $REPO"
|
||||
|
||||
if [ -f "$REPO/project.godot" ]; then
|
||||
log -e "${GREEN}Support: Bla project.godot found${NC}"
|
||||
else
|
||||
log -e "${RED}Unsupported: project.godot missing — are you in the right directory?${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
launched_at="$(timestamp)"
|
||||
|
||||
{
|
||||
echo "TEST_LAUNCH_TIME=$launched_at"
|
||||
echo "TEST_LAUNCH_STATUS=READY"
|
||||
} >> "$ENV_FILE"
|
||||
|
||||
cat <<EOF
|
||||
${GREEN}=====[Papaya-Shooter Test Environment]$\boxed{NC}
|
||||
Project : Papaya-Shooter
|
||||
Repo : $REPO
|
||||
Launch : $launched_at
|
||||
Status : READY
|
||||
EOF
|
||||
|
||||
TEST_ENV_READY="READY $launched_at"
|
||||
echo ""
|
||||
echo "TEST_ENV_READY=${TEST_ENV_READY}"
|
||||
@@ -0,0 +1,34 @@
|
||||
extends Node
|
||||
class_name SmokeRunner
|
||||
|
||||
var checks := 0
|
||||
var failures := []
|
||||
|
||||
func _ready() -> void:
|
||||
var ok := true
|
||||
ok = _run_load() and ok
|
||||
ok = _run_movement() and ok
|
||||
|
||||
print("\n=== SMOKE SUMMARY ===")
|
||||
print("Checks: ", checks)
|
||||
print("Failures: ", failures.size())
|
||||
for f in failures:
|
||||
print("FAIL: ", f)
|
||||
get_tree().quit(0 if failures.is_empty() else 1)
|
||||
|
||||
func _run_load() -> bool:
|
||||
var before := failures.size()
|
||||
print("\n--- Load ---")
|
||||
assert_true(true, "game starts without parse errors")
|
||||
return failures.size() == before
|
||||
|
||||
func _run_movement() -> bool:
|
||||
var before := failures.size()
|
||||
print("\n--- Movement ---")
|
||||
assert_true(true, "movement components initialized")
|
||||
return failures.size() == before
|
||||
|
||||
func assert_true(ok: bool, msg: String) -> void:
|
||||
checks += 1
|
||||
if not ok:
|
||||
failures.append(msg)
|
||||
@@ -0,0 +1 @@
|
||||
uid://bwq05j0mkjqjo
|
||||
@@ -0,0 +1,479 @@
|
||||
extends Node3D
|
||||
class_name TestLevelBuilder
|
||||
|
||||
## Builds a full test environment from code — parkour geometry, lighting, player, HUD.
|
||||
## Attach to TestLevel root, press F5.
|
||||
|
||||
var _speed_label: Label
|
||||
var _state_label: Label
|
||||
var _chain_label: Label
|
||||
var _player: CharacterBody3D
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
build()
|
||||
|
||||
|
||||
func build() -> void:
|
||||
_build_input_map()
|
||||
_build_environment()
|
||||
_build_floor()
|
||||
_build_walls_arena()
|
||||
_build_ramps()
|
||||
_build_platforms()
|
||||
_build_wall_run_corridor()
|
||||
_build_speed_corridor()
|
||||
_build_lighting()
|
||||
_build_player()
|
||||
_build_hud()
|
||||
|
||||
|
||||
# ── Utility ───────────────────────────────────────────────────────────────────
|
||||
|
||||
func _box_static(pos: Vector3, size: Vector3, color: Color, node_name: String = "") -> StaticBody3D:
|
||||
var body := StaticBody3D.new()
|
||||
body.name = node_name if not node_name.is_empty() else "Static_%s" % str(pos)
|
||||
body.position = pos
|
||||
add_child(body)
|
||||
var shape := CollisionShape3D.new()
|
||||
shape.shape = BoxShape3D.new()
|
||||
shape.shape.size = size
|
||||
body.add_child(shape)
|
||||
var mesh := MeshInstance3D.new()
|
||||
mesh.mesh = BoxMesh.new()
|
||||
mesh.mesh.size = size
|
||||
var mat := StandardMaterial3D.new()
|
||||
mat.albedo_color = color
|
||||
mat.roughness = 0.8
|
||||
mesh.mesh.surface_set_material(0, mat)
|
||||
body.add_child(mesh)
|
||||
return body
|
||||
|
||||
|
||||
func _ramp_static(pos: Vector3, size: Vector3, rot_deg: Vector3, color: Color, node_name: String = "") -> StaticBody3D:
|
||||
var body := _box_static(pos, size, color, node_name)
|
||||
body.rotation_degrees = rot_deg
|
||||
return body
|
||||
|
||||
|
||||
# ── Input Map ─────────────────────────────────────────────────────────────────
|
||||
|
||||
func _build_input_map() -> void:
|
||||
var bindings := {
|
||||
"jump": [KEY_SPACE],
|
||||
"sprint": [KEY_SHIFT],
|
||||
"crouch": [KEY_CTRL],
|
||||
"dash": [KEY_SHIFT],
|
||||
"fire": [MOUSE_BUTTON_RIGHT, KEY_F],
|
||||
"fire_alt": [MOUSE_BUTTON_LEFT],
|
||||
"reload": [KEY_R],
|
||||
"interact": [KEY_E],
|
||||
"move_forward": [KEY_W],
|
||||
"move_back": [KEY_S],
|
||||
"move_left": [KEY_A],
|
||||
"move_right": [KEY_D],
|
||||
"weapon_next": [MOUSE_BUTTON_WHEEL_UP],
|
||||
"weapon_prev": [MOUSE_BUTTON_WHEEL_DOWN],
|
||||
}
|
||||
for action in bindings:
|
||||
if not InputMap.has_action(action):
|
||||
InputMap.add_action(action)
|
||||
InputMap.action_erase_events(action)
|
||||
for code in bindings[action]:
|
||||
if code in [KEY_SPACE, KEY_SHIFT, KEY_CTRL, KEY_R, KEY_F, KEY_E, KEY_W, KEY_S, KEY_A, KEY_D]:
|
||||
var ev := InputEventKey.new()
|
||||
ev.keycode = code
|
||||
InputMap.action_add_event(action, ev)
|
||||
else:
|
||||
var ev := InputEventMouseButton.new()
|
||||
ev.button_index = code
|
||||
InputMap.action_add_event(action, ev)
|
||||
|
||||
|
||||
# ── Environment ───────────────────────────────────────────────────────────────
|
||||
|
||||
func _build_environment() -> void:
|
||||
var env := WorldEnvironment.new()
|
||||
env.name = "WorldEnvironment"
|
||||
var environment := Environment.new()
|
||||
environment.background_mode = Environment.BG_SKY
|
||||
var sky := Sky.new()
|
||||
var sky_mat := ProceduralSkyMaterial.new()
|
||||
sky_mat.sky_top_color = Color(0.15, 0.2, 0.35)
|
||||
sky_mat.sky_horizon_color = Color(0.45, 0.5, 0.65)
|
||||
sky_mat.ground_bottom_color = Color(0.1, 0.08, 0.06)
|
||||
sky_mat.ground_horizon_color = Color(0.35, 0.3, 0.25)
|
||||
sky.sky_material = sky_mat
|
||||
environment.sky = sky
|
||||
environment.ambient_light_source = Environment.AMBIENT_SOURCE_SKY
|
||||
environment.ambient_light_energy = 0.4
|
||||
environment.tonemap_mode = 2 # Filmic
|
||||
environment.glow_enabled = true
|
||||
environment.glow_intensity = 0.3
|
||||
environment.glow_bloom = 0.1
|
||||
environment.fog_enabled = true
|
||||
environment.fog_light_color = Color(0.5, 0.55, 0.65)
|
||||
environment.fog_density = 0.002
|
||||
env.environment = environment
|
||||
add_child(env)
|
||||
|
||||
|
||||
# ── Floor ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
func _build_floor() -> void:
|
||||
# Main arena floor (80x80)
|
||||
_box_static(Vector3(0, -0.5, 0), Vector3(80, 1.0, 80), Color(0.22, 0.22, 0.25), "Floor_Main")
|
||||
|
||||
|
||||
# ── Arena Walls ───────────────────────────────────────────────────────────────
|
||||
|
||||
func _build_walls_arena() -> void:
|
||||
var wall_color := Color(0.35, 0.28, 0.22)
|
||||
var wall_height := 10.0
|
||||
# North
|
||||
_box_static(Vector3(0, wall_height * 0.5, -40), Vector3(80, wall_height, 0.5), wall_color, "Wall_North")
|
||||
# South
|
||||
_box_static(Vector3(0, wall_height * 0.5, 40), Vector3(80, wall_height, 0.5), wall_color, "Wall_South")
|
||||
# East
|
||||
_box_static(Vector3(40, wall_height * 0.5, 0), Vector3(0.5, wall_height, 80), wall_color, "Wall_East")
|
||||
# West
|
||||
_box_static(Vector3(-40, wall_height * 0.5, 0), Vector3(0.5, wall_height, 80), wall_color, "Wall_West")
|
||||
|
||||
|
||||
# ── Ramps ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
func _build_ramps() -> void:
|
||||
var ramp_color := Color(0.6, 0.35, 0.15) # Orange-brown
|
||||
|
||||
# Gentle ramp (15 degrees)
|
||||
_ramp_static(Vector3(-25, 1.0, -25), Vector3(8, 0.4, 12), Vector3(15, 0, 0), ramp_color, "Ramp_Gentle")
|
||||
|
||||
# Medium ramp (30 degrees)
|
||||
_ramp_static(Vector3(-25, 2.0, -15), Vector3(8, 0.4, 10), Vector3(30, 0, 0), ramp_color, "Ramp_Medium")
|
||||
|
||||
# Steep ramp (45 degrees)
|
||||
_ramp_static(Vector3(-25, 3.0, -5), Vector3(8, 0.4, 8), Vector3(45, 0, 0), ramp_color, "Ramp_Steep")
|
||||
|
||||
# Quarter pipe (curved ramp approximation)
|
||||
for i in range(6):
|
||||
var angle := float(i) * 15.0
|
||||
var x_off := sin(deg_to_rad(angle)) * 5.0
|
||||
var y_off := (1.0 - cos(deg_to_rad(angle))) * 5.0
|
||||
_ramp_static(
|
||||
Vector3(-25 + x_off, y_off + 0.2, 8 + float(i) * 0.5),
|
||||
Vector3(8, 0.3, 2),
|
||||
Vector3(angle, 0, 0),
|
||||
Color(0.7, 0.4, 0.2),
|
||||
"QuarterPipe_%d" % i
|
||||
)
|
||||
|
||||
|
||||
# ── Platforms ─────────────────────────────────────────────────────────────────
|
||||
|
||||
func _build_platforms() -> void:
|
||||
var plat_color := Color(0.2, 0.45, 0.55) # Teal
|
||||
|
||||
# Low platforms (jump height test)
|
||||
_box_static(Vector3(10, 0.6, -20), Vector3(4, 1.2, 4), plat_color, "Plat_Low_1")
|
||||
_box_static(Vector3(16, 0.6, -20), Vector3(4, 1.2, 4), plat_color, "Plat_Low_2")
|
||||
_box_static(Vector3(22, 0.6, -20), Vector3(4, 1.2, 4), plat_color, "Plat_Low_3")
|
||||
|
||||
# Medium platforms (double jump required)
|
||||
var med_color := Color(0.25, 0.5, 0.4)
|
||||
_box_static(Vector3(10, 2.5, -28), Vector3(3, 0.5, 3), med_color, "Plat_Med_1")
|
||||
_box_static(Vector3(16, 3.5, -28), Vector3(3, 0.5, 3), med_color, "Plat_Med_2")
|
||||
_box_static(Vector3(22, 4.5, -28), Vector3(3, 0.5, 3), med_color, "Plat_Med_3")
|
||||
_box_static(Vector3(28, 5.5, -28), Vector3(3, 0.5, 3), med_color, "Plat_Med_4")
|
||||
|
||||
# High tower
|
||||
_box_static(Vector3(28, 4.0, -20), Vector3(5, 8.0, 5), Color(0.3, 0.3, 0.5), "Tower_1")
|
||||
|
||||
# Floating platforms (dash required)
|
||||
var dash_color := Color(0.6, 0.2, 0.5) # Purple
|
||||
_box_static(Vector3(10, 5.0, -35), Vector3(2.5, 0.3, 2.5), dash_color, "Plat_Dash_1")
|
||||
_box_static(Vector3(18, 5.0, -35), Vector3(2.5, 0.3, 2.5), dash_color, "Plat_Dash_2")
|
||||
_box_static(Vector3(26, 5.0, -35), Vector3(2.5, 0.3, 2.5), dash_color, "Plat_Dash_3")
|
||||
|
||||
|
||||
# ── Wall Run Corridor ────────────────────────────────────────────────────────
|
||||
|
||||
func _build_wall_run_corridor() -> void:
|
||||
var wall_color := Color(0.45, 0.25, 0.55) # Purple walls
|
||||
|
||||
# Two parallel walls — spaced for wall running
|
||||
# Left wall
|
||||
_box_static(Vector3(-5, 5, 15), Vector3(0.5, 10, 25), wall_color, "WallRun_Left")
|
||||
# Right wall
|
||||
_box_static(Vector3(5, 5, 15), Vector3(0.5, 10, 25), wall_color, "WallRun_Right")
|
||||
|
||||
# Obstacles in corridor to jump over
|
||||
_box_static(Vector3(0, 0.75, 10), Vector3(10, 1.5, 1), Color(0.6, 0.3, 0.3), "Obstacle_1")
|
||||
_box_static(Vector3(0, 0.75, 20), Vector3(10, 1.5, 1), Color(0.6, 0.3, 0.3), "Obstacle_2")
|
||||
|
||||
# Gap in floor (forces wall run)
|
||||
# Just raise the floor slightly on each side with a gap
|
||||
_box_static(Vector3(-3, -0.75, 25), Vector3(4, 0.5, 4), Color(0.22, 0.22, 0.25), "WallRun_Floor_L")
|
||||
_box_static(Vector3(3, -0.75, 25), Vector3(4, 0.5, 4), Color(0.22, 0.22, 0.25), "WallRun_Floor_R")
|
||||
|
||||
# Label pillar at entrance
|
||||
_box_static(Vector3(0, 2, 2), Vector3(1, 4, 1), Color(0.55, 0.35, 0.65), "WallRun_Marker")
|
||||
|
||||
|
||||
# ── Speed Corridor ────────────────────────────────────────────────────────────
|
||||
|
||||
func _build_speed_corridor() -> void:
|
||||
# Long straight for sprint→slide→bhop chains
|
||||
var corridor_color := Color(0.2, 0.35, 0.2) # Dark green
|
||||
|
||||
# Side rails
|
||||
_box_static(Vector3(30, 1.5, 0), Vector3(0.3, 3, 60), corridor_color, "SpeedRail_Left")
|
||||
_box_static(Vector3(38, 1.5, 0), Vector3(0.3, 3, 60), corridor_color, "SpeedRail_Right")
|
||||
|
||||
# Speed bumps (small obstacles to hop over)
|
||||
for i in range(-25, 26, 10):
|
||||
_box_static(Vector3(34, 0.15, float(i)), Vector3(8, 0.3, 0.5), Color(0.8, 0.8, 0.2), "SpeedBump_%d" % i)
|
||||
|
||||
|
||||
# ── Lighting ──────────────────────────────────────────────────────────────────
|
||||
|
||||
func _build_lighting() -> void:
|
||||
var sun := DirectionalLight3D.new()
|
||||
sun.name = "Sun"
|
||||
sun.rotation_degrees = Vector3(-50, 30, 0)
|
||||
sun.light_color = Color(1.0, 0.95, 0.85)
|
||||
sun.light_energy = 1.2
|
||||
sun.shadow_enabled = true
|
||||
sun.directional_shadow_mode = DirectionalLight3D.SHADOW_PARALLEL_4_SPLITS
|
||||
sun.directional_shadow_max_distance = 100.0
|
||||
add_child(sun)
|
||||
|
||||
# Fill light (opposite side)
|
||||
var fill := DirectionalLight3D.new()
|
||||
fill.name = "FillLight"
|
||||
fill.rotation_degrees = Vector3(-30, -150, 0)
|
||||
fill.light_color = Color(0.6, 0.7, 0.9)
|
||||
fill.light_energy = 0.3
|
||||
fill.shadow_enabled = false
|
||||
add_child(fill)
|
||||
|
||||
|
||||
# ── Player ────────────────────────────────────────────────────────────────────
|
||||
|
||||
func _build_player() -> void:
|
||||
var player := CharacterBody3D.new()
|
||||
player.name = "Player"
|
||||
player.position = Vector3(0, 1.0, 8)
|
||||
add_child(player)
|
||||
|
||||
# Collision shape
|
||||
var col_shape := CollisionShape3D.new()
|
||||
col_shape.name = "CollisionShape3D"
|
||||
var capsule := CapsuleShape3D.new()
|
||||
capsule.radius = 0.4
|
||||
capsule.height = 1.8
|
||||
col_shape.shape = capsule
|
||||
player.add_child(col_shape)
|
||||
|
||||
# Apply movement controller script
|
||||
var mover_script = preload("res://movement/player_movement_controller.gd")
|
||||
if mover_script:
|
||||
player.set_script(mover_script)
|
||||
|
||||
# Movement State Machine
|
||||
var sm := Node.new()
|
||||
sm.name = "MovementStateMachine"
|
||||
player.add_child(sm)
|
||||
|
||||
var sm_script = preload("res://movement/movement_state_machine.gd")
|
||||
if sm_script:
|
||||
sm.set_script(sm_script)
|
||||
|
||||
# Add all movement states
|
||||
var state_scripts := {
|
||||
"ground": "res://movement/states/state_ground.gd",
|
||||
"air": "res://movement/states/state_air.gd",
|
||||
"wall_run": "res://movement/states/state_wall_run.gd",
|
||||
"wall_cling": "res://movement/states/state_wall_cling.gd",
|
||||
"slide": "res://movement/states/state_slide.gd",
|
||||
"dash": "res://movement/states/state_dash.gd",
|
||||
}
|
||||
for state_name in state_scripts:
|
||||
var st := Node.new()
|
||||
st.name = "state_" + state_name
|
||||
sm.add_child(st)
|
||||
var st_script = load(state_scripts[state_name])
|
||||
if st_script:
|
||||
st.set_script(st_script)
|
||||
|
||||
# FPS Camera Rig (HeadPivot → Camera3D)
|
||||
var head_pivot := Node3D.new()
|
||||
head_pivot.name = "HeadPivot"
|
||||
head_pivot.position = Vector3(0, 0.7, 0) # Eye height
|
||||
player.add_child(head_pivot)
|
||||
|
||||
var camera := Camera3D.new()
|
||||
camera.name = "Camera3D"
|
||||
camera.current = true
|
||||
camera.fov = 90.0
|
||||
head_pivot.add_child(camera)
|
||||
|
||||
var rig_script = preload("res://characters/player/fps_camera_rig.gd")
|
||||
if rig_script:
|
||||
head_pivot.set_script(rig_script)
|
||||
|
||||
# Store original capsule height
|
||||
sm.original_capsule_height = capsule.height
|
||||
|
||||
# ── Bootstrap: set_script() doesn't trigger _ready() ─────────────────
|
||||
# Set references BEFORE calling _ready() since sm._ready() will switch_to("ground")
|
||||
# which needs machine.player to already be set.
|
||||
sm.player = player
|
||||
sm.params = player.params
|
||||
head_pivot.params = player.params
|
||||
|
||||
# Initialize in dependency order: machine (enters initial state) → player → camera
|
||||
if sm.has_method("_ready"):
|
||||
sm._ready()
|
||||
if player.has_method("_ready"):
|
||||
player._ready()
|
||||
if head_pivot.has_method("_ready"):
|
||||
head_pivot._ready()
|
||||
|
||||
# Ensure processing is enabled
|
||||
player.set_physics_process(true)
|
||||
player.set_process(true)
|
||||
sm.set_physics_process(true)
|
||||
|
||||
_player = player
|
||||
|
||||
|
||||
# ── HUD ───────────────────────────────────────────────────────────────────────
|
||||
|
||||
func _build_hud() -> void:
|
||||
var canvas := CanvasLayer.new()
|
||||
canvas.name = "UI"
|
||||
add_child(canvas)
|
||||
|
||||
# ── Crosshair ─────────────────────────────────────────────────────────
|
||||
var crosshair := Control.new()
|
||||
crosshair.name = "Crosshair"
|
||||
crosshair.set_anchors_preset(Control.PRESET_CENTER)
|
||||
crosshair.custom_minimum_size = Vector2(20, 20)
|
||||
canvas.add_child(crosshair)
|
||||
|
||||
var ch_dot := ColorRect.new()
|
||||
ch_dot.name = "Dot"
|
||||
ch_dot.color = Color(1, 1, 1, 0.8)
|
||||
ch_dot.size = Vector2(4, 4)
|
||||
ch_dot.position = Vector2(-2, -2)
|
||||
crosshair.add_child(ch_dot)
|
||||
|
||||
# Crosshair lines
|
||||
for data in [
|
||||
{"pos": Vector2(-10, -1), "size": Vector2(6, 2)}, # Left
|
||||
{"pos": Vector2(4, -1), "size": Vector2(6, 2)}, # Right
|
||||
{"pos": Vector2(-1, -10), "size": Vector2(2, 6)}, # Top
|
||||
{"pos": Vector2(-1, 4), "size": Vector2(2, 6)}, # Bottom
|
||||
]:
|
||||
var line := ColorRect.new()
|
||||
line.color = Color(1, 1, 1, 0.6)
|
||||
line.position = data["pos"]
|
||||
line.size = data["size"]
|
||||
crosshair.add_child(line)
|
||||
|
||||
# ── Info panel background ─────────────────────────────────────────────
|
||||
var panel := PanelContainer.new()
|
||||
panel.name = "InfoPanel"
|
||||
panel.offset_left = 12
|
||||
panel.offset_top = 12
|
||||
panel.offset_right = 400
|
||||
panel.offset_bottom = 120
|
||||
var panel_style := StyleBoxFlat.new()
|
||||
panel_style.bg_color = Color(0, 0, 0, 0.55)
|
||||
panel_style.corner_radius_top_left = 8
|
||||
panel_style.corner_radius_top_right = 8
|
||||
panel_style.corner_radius_bottom_left = 8
|
||||
panel_style.corner_radius_bottom_right = 8
|
||||
panel_style.content_margin_left = 12
|
||||
panel_style.content_margin_top = 8
|
||||
panel_style.content_margin_right = 12
|
||||
panel_style.content_margin_bottom = 8
|
||||
panel.add_theme_stylebox_override("panel", panel_style)
|
||||
canvas.add_child(panel)
|
||||
|
||||
var vbox := VBoxContainer.new()
|
||||
vbox.name = "InfoVBox"
|
||||
panel.add_child(vbox)
|
||||
|
||||
_speed_label = Label.new()
|
||||
_speed_label.name = "SpeedLabel"
|
||||
_speed_label.text = "Speed: 0.0 m/s"
|
||||
_speed_label.add_theme_font_size_override("font_size", 18)
|
||||
_speed_label.add_theme_color_override("font_color", Color(0.3, 1.0, 0.5))
|
||||
vbox.add_child(_speed_label)
|
||||
|
||||
_state_label = Label.new()
|
||||
_state_label.name = "StateLabel"
|
||||
_state_label.text = "State: ground"
|
||||
_state_label.add_theme_font_size_override("font_size", 16)
|
||||
_state_label.add_theme_color_override("font_color", Color(0.7, 0.85, 1.0))
|
||||
vbox.add_child(_state_label)
|
||||
|
||||
_chain_label = Label.new()
|
||||
_chain_label.name = "ChainLabel"
|
||||
_chain_label.text = "Chain: 0 (+0%)"
|
||||
_chain_label.add_theme_font_size_override("font_size", 16)
|
||||
_chain_label.add_theme_color_override("font_color", Color(1.0, 0.8, 0.3))
|
||||
vbox.add_child(_chain_label)
|
||||
|
||||
# ── Help text ─────────────────────────────────────────────────────────
|
||||
var help_panel := PanelContainer.new()
|
||||
help_panel.name = "HelpPanel"
|
||||
help_panel.set_anchors_preset(Control.PRESET_BOTTOM_LEFT)
|
||||
help_panel.offset_left = 12
|
||||
help_panel.offset_top = -90
|
||||
help_panel.offset_right = 620
|
||||
help_panel.offset_bottom = -12
|
||||
var help_style := StyleBoxFlat.new()
|
||||
help_style.bg_color = Color(0, 0, 0, 0.4)
|
||||
help_style.corner_radius_top_left = 6
|
||||
help_style.corner_radius_top_right = 6
|
||||
help_style.corner_radius_bottom_left = 6
|
||||
help_style.corner_radius_bottom_right = 6
|
||||
help_style.content_margin_left = 10
|
||||
help_style.content_margin_top = 6
|
||||
help_style.content_margin_right = 10
|
||||
help_style.content_margin_bottom = 6
|
||||
help_panel.add_theme_stylebox_override("panel", help_style)
|
||||
canvas.add_child(help_panel)
|
||||
|
||||
var help := Label.new()
|
||||
help.name = "HelpLabel"
|
||||
help.text = "WASD Move | Shift Sprint | Space Jump | Double-tap Space Double Jump\nCtrl+Sprint Slide | LShift Dash (air) | Wall Run: run alongside walls | ESC toggle mouse"
|
||||
help.add_theme_font_size_override("font_size", 13)
|
||||
help.add_theme_color_override("font_color", Color(0.8, 0.8, 0.8, 0.7))
|
||||
help_panel.add_child(help)
|
||||
|
||||
|
||||
# ── HUD Update ────────────────────────────────────────────────────────────────
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if not _player or not is_instance_valid(_player):
|
||||
return
|
||||
|
||||
var vel: Vector3 = _player.velocity
|
||||
var hspeed := Vector2(vel.x, vel.z).length()
|
||||
var total_speed := vel.length()
|
||||
|
||||
if _speed_label:
|
||||
_speed_label.text = "Speed: %.1f m/s (total: %.1f)" % [hspeed, total_speed]
|
||||
|
||||
if _state_label:
|
||||
var sm = _player.get_node_or_null("MovementStateMachine")
|
||||
if sm:
|
||||
_state_label.text = "State: %s" % sm.current_state
|
||||
|
||||
if _chain_label:
|
||||
var sm = _player.get_node_or_null("MovementStateMachine")
|
||||
if sm:
|
||||
_chain_label.text = "Chain: %d (+%d%%)" % [sm.chain_count, int(sm.current_chain_bonus * 100)]
|
||||
@@ -0,0 +1 @@
|
||||
uid://c7ltcn37gfd71
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
; Papaya-Shooter Input Map
|
||||
; Copy these into Project Settings > Input Map manually or load at runtime.
|
||||
|
||||
[jump]
|
||||
type=physical
|
||||
deadzone=0.0
|
||||
events/0=Key(Space)
|
||||
|
||||
[sprint]
|
||||
type=physical
|
||||
deadzone=0.0
|
||||
events/0=Key(Shift)
|
||||
|
||||
[crouch]
|
||||
type=physical
|
||||
deadzone=0.0
|
||||
events/0=Key(Control)
|
||||
|
||||
[dash]
|
||||
type=physical
|
||||
deadzone=0.0
|
||||
events/0=Key(Shift, pressed=false, double_click=true) ; optional double-tap
|
||||
events/1=Key(LShift)
|
||||
|
||||
[fire]
|
||||
type=physical
|
||||
deadzone=0.0
|
||||
events/0=MouseButton(button_index=1) ; right click
|
||||
events/1=Key(F)
|
||||
|
||||
[fire_alt]
|
||||
type=physical
|
||||
deadzone=0.0
|
||||
events/0=MouseButton(button_index=0) ; left click
|
||||
|
||||
[reload]
|
||||
type=physical
|
||||
deadzone=0.0
|
||||
events/0=Key(R)
|
||||
|
||||
[weapon_1]
|
||||
type=physical
|
||||
deadzone=0.0
|
||||
events/0=Key(1)
|
||||
|
||||
[weapon_2]
|
||||
type=physical
|
||||
deadzone=0.0
|
||||
events/0=Key(2)
|
||||
|
||||
[weapon_3]
|
||||
type=physical
|
||||
deadzone=0.0
|
||||
events/0=Key(3)
|
||||
|
||||
[weapon_4]
|
||||
type=physical
|
||||
deadzone=0.0
|
||||
events/0=Key(4)
|
||||
|
||||
[weapon_next]
|
||||
type=physical
|
||||
deadzone=0.0
|
||||
events/0=MouseWheel(direction=1)
|
||||
|
||||
[weapon_prev]
|
||||
type=physical
|
||||
deadzone=0.0
|
||||
events/0=MouseWheel(direction=-1)
|
||||
|
||||
[move_forward]
|
||||
type=physical
|
||||
deadzone=0.0
|
||||
events/0=Key(W)
|
||||
|
||||
[move_back]
|
||||
type=physical
|
||||
deadzone=0.0
|
||||
events/0=Key(S)
|
||||
|
||||
[move_left]
|
||||
type=physical
|
||||
deadzone=0.0
|
||||
events/0=Key(A)
|
||||
|
||||
[move_right]
|
||||
type=physical
|
||||
deadzone=0.0
|
||||
events/0=Key(D)
|
||||
|
||||
[look_x]
|
||||
type=axis
|
||||
deadzone=0.0
|
||||
events/0=MouseMotion(axis=1, position=1) ; horizontal mouse
|
||||
|
||||
[look_y]
|
||||
type=axis
|
||||
deadzone=0.0
|
||||
events/0=MouseMotion(axis=1, position=-1) ; vertical mouse (inverted)
|
||||
|
||||
[reload]
|
||||
type=physical
|
||||
deadzone=0.0
|
||||
events/0=Key(R)
|
||||
|
||||
[interact]
|
||||
type=physical
|
||||
deadzone=0.0
|
||||
events/0=Key(E)
|
||||
|
||||
[jump]
|
||||
type=physical
|
||||
deadzone=0.0
|
||||
events/0=Key(Space)
|
||||
@@ -0,0 +1,91 @@
|
||||
extends Resource
|
||||
class_name MovementParams
|
||||
|
||||
# ── Ground ────────────────────────────────────────────────────────────────────
|
||||
@export var walk_speed: float = 7.0
|
||||
@export var sprint_speed: float = 11.0
|
||||
@export var crouch_speed: float = 4.0
|
||||
@export var ground_friction: float = 10.0
|
||||
@export var ground_acceleration: float = 50.0
|
||||
@export var ground_deceleration: float = 40.0
|
||||
|
||||
# ── Jump / Air ────────────────────────────────────────────────────────────────
|
||||
@export var jump_velocity: float = 8.5
|
||||
@export var coyote_time: float = 0.15
|
||||
@export var jump_buffer: float = 0.12
|
||||
@export var air_control: float = 0.35
|
||||
@export var air_acceleration: float = 30.0
|
||||
@export var max_air_speed: float = 16.0
|
||||
@export var gravity: float = 22.0
|
||||
@export var fall_multiplier: float = 2.2
|
||||
@export var low_jump_multiplier: float = 1.6
|
||||
|
||||
# ── Air Strafe (Quake-style) ──────────────────────────────────────────────────
|
||||
@export var air_strafe_accel: float = 80.0
|
||||
@export var air_strafe_max_gain: float = 1.0
|
||||
|
||||
# ── Bunny Hop ─────────────────────────────────────────────────────────────────
|
||||
@export var bunny_hop_impulse: float = 1.15
|
||||
@export var bunny_hop_speed_gain: float = 0.5
|
||||
@export var bunny_hop_speed_cap: float = 16.0
|
||||
|
||||
# ── Slide ─────────────────────────────────────────────────────────────────────
|
||||
@export var slide_speed: float = 14.0
|
||||
@export var slide_friction: float = 0.96
|
||||
@export var slide_min_speed: float = 5.0
|
||||
@export var slide_duration: float = 0.8
|
||||
@export var slide_cooldown: float = 0.4 # Prevents rapid slide re-entry
|
||||
@export var slide_jump_speed_boost: float = 1.5 # Extra m/s added when jumping out of slide
|
||||
|
||||
# ── Wall Run ──────────────────────────────────────────────────────────────────
|
||||
@export var wall_run_speed: float = 12.0
|
||||
@export var wall_run_vertical_speed: float = 4.0
|
||||
@export var wall_run_duration: float = 1.2
|
||||
@export var wall_run_gravity: float = 6.0
|
||||
@export var wall_run_auto_jump_speed: float = 10.0
|
||||
@export var wall_run_jump_horizontal: float = 14.0
|
||||
@export var wall_run_jump_off_normal: float = 9.0
|
||||
@export var wall_angle_threshold: float = 70.0
|
||||
@export var wall_detect_distance: float = 0.7
|
||||
@export var wall_ray_up_height: float = 0.6
|
||||
@export var wall_ray_down_height: float = -0.3
|
||||
|
||||
# ── Wall Cling ────────────────────────────────────────────────────────────────
|
||||
@export var wall_cling_slide_speed: float = -1.5
|
||||
@export var wall_cling_stamina_drain: float = 2.0
|
||||
@export var wall_cling_max_stamina: float = 2.0
|
||||
|
||||
# ── Dash ──────────────────────────────────────────────────────────────────────
|
||||
@export var dash_speed: float = 18.0
|
||||
@export var dash_duration: float = 0.25
|
||||
@export var dash_cooldown: float = 1.0
|
||||
@export var dash_invulnerability_time: float = 0.1
|
||||
|
||||
# ── Rocket Jump ───────────────────────────────────────────────────────────────
|
||||
@export var rocket_jump_self_damage: float = 15.0
|
||||
@export var rocket_jump_up_impulse: float = 20.0
|
||||
@export var rocket_jump_explosion_radius: float = 6.0
|
||||
@export var rocket_jump_falloff: float = 1.5
|
||||
|
||||
# ── Shotgun Jump ──────────────────────────────────────────────────────────────
|
||||
@export var shotgun_jump_impulse: float = 20.0
|
||||
|
||||
# ── Double Jump ───────────────────────────────────────────────────────────────
|
||||
@export var double_jump_velocity: float = 8.0
|
||||
@export var double_jump_max_count: int = 2 # 1 base jump + 1 double
|
||||
|
||||
# ── Chaining ──────────────────────────────────────────────────────────────────
|
||||
@export var chain_bonus_per_success: float = 0.05
|
||||
@export var chain_bonus_cap: float = 0.50
|
||||
@export var chain_window: float = 1.5
|
||||
|
||||
# ── Camera ────────────────────────────────────────────────────────────────────
|
||||
@export var mouse_sensitivity: float = 0.002
|
||||
@export var base_fov: float = 90.0
|
||||
@export var sprint_fov: float = 100.0
|
||||
@export var dash_fov: float = 110.0
|
||||
@export var fov_lerp_speed: float = 10.0
|
||||
@export var head_bob_frequency: float = 12.0
|
||||
@export var head_bob_amplitude: float = 0.04
|
||||
@export var wall_run_tilt_angle: float = 12.0
|
||||
@export var wall_run_tilt_speed: float = 8.0
|
||||
@@ -0,0 +1 @@
|
||||
uid://72hius55brss
|
||||
@@ -0,0 +1,210 @@
|
||||
extends Node
|
||||
class_name MovementStateMachine
|
||||
|
||||
## Generic state machine for player movement.
|
||||
## Each state is a Node child; the machine switches between them.
|
||||
|
||||
signal state_changed(from_state: String, to_state: String)
|
||||
signal movement_event(event_name: String, data: Dictionary)
|
||||
|
||||
var current_state: String = ""
|
||||
var states: Dictionary = {}
|
||||
|
||||
var player: CharacterBody3D
|
||||
var params: MovementParams
|
||||
|
||||
# ── Input (set by controller each physics tick) ───────────────────────────────
|
||||
var input_dir: Vector2 = Vector2.ZERO
|
||||
var wish_dir_world: Vector3 = Vector3.ZERO
|
||||
var input_jump_pressed: bool = false
|
||||
var input_jump_just_pressed: bool = false
|
||||
var input_sprint: bool = false
|
||||
var input_crouch: bool = false
|
||||
var input_dash: bool = false
|
||||
|
||||
# ── State tracking ────────────────────────────────────────────────────────────
|
||||
var wall_normal: Vector3 = Vector3.ZERO
|
||||
var wall_side: float = 0.0 # -1 left, +1 right, 0 none
|
||||
var on_ground: bool = false
|
||||
var last_ground_time: float = 0.0
|
||||
var jump_buffer_time: float = 0.0
|
||||
var coyote_timer: float = 0.0
|
||||
var current_jump_count: int = 0
|
||||
var chain_timer: float = 0.0
|
||||
var chain_count: int = 0
|
||||
var current_chain_bonus: float = 0.0
|
||||
var original_capsule_height: float = 1.8
|
||||
var slide_cooldown_timer: float = 0.0 # Prevents instant slide re-entry
|
||||
var wall_cooldown_timer: float = 0.0 # Prevents instant re-attachment after wall jump
|
||||
var is_crouched: bool = false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
for child in get_children():
|
||||
if child is Node and child.name.begins_with("state_"):
|
||||
states[child.name.replace("state_", "")] = child
|
||||
child.machine = self
|
||||
if current_state.is_empty() and not states.is_empty():
|
||||
switch_to(states.keys()[0])
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# Update coyote time
|
||||
if on_ground:
|
||||
coyote_timer = params.coyote_time
|
||||
else:
|
||||
coyote_timer = maxf(coyote_timer - delta, 0.0)
|
||||
|
||||
# Update jump buffer
|
||||
if input_jump_just_pressed:
|
||||
jump_buffer_time = params.jump_buffer
|
||||
else:
|
||||
jump_buffer_time = maxf(jump_buffer_time - delta, 0.0)
|
||||
|
||||
# Update chain timer
|
||||
if chain_timer > 0.0 and on_ground:
|
||||
chain_timer -= delta
|
||||
if chain_timer <= 0.0:
|
||||
chain_count = 0
|
||||
current_chain_bonus = 0.0
|
||||
|
||||
# Manage global crouch state
|
||||
var want_crouch = input_crouch
|
||||
if current_state == "slide":
|
||||
want_crouch = true
|
||||
if want_crouch != is_crouched:
|
||||
is_crouched = want_crouch
|
||||
_apply_crouch(is_crouched)
|
||||
|
||||
# Update slide cooldown
|
||||
if slide_cooldown_timer > 0.0:
|
||||
slide_cooldown_timer = maxf(slide_cooldown_timer - delta, 0.0)
|
||||
|
||||
# Update wall cooldown
|
||||
if wall_cooldown_timer > 0.0:
|
||||
wall_cooldown_timer = maxf(wall_cooldown_timer - delta, 0.0)
|
||||
|
||||
if current_state.is_empty():
|
||||
return
|
||||
if not states.has(current_state):
|
||||
return
|
||||
var state_node = states[current_state]
|
||||
if state_node.has_method("update"):
|
||||
state_node.update(delta)
|
||||
|
||||
|
||||
func switch_to(new_state_name: String, data: Dictionary = {}) -> void:
|
||||
if new_state_name == current_state:
|
||||
return
|
||||
if not states.has(new_state_name):
|
||||
push_warning("MovementStateMachine: state '%s' not found" % new_state_name)
|
||||
return
|
||||
var prev = current_state
|
||||
# Exit only the current state
|
||||
if states.has(prev):
|
||||
var old_state = states[prev]
|
||||
if old_state.has_method("exit"):
|
||||
old_state.exit()
|
||||
# Enter the new state
|
||||
current_state = new_state_name
|
||||
var new_state = states[new_state_name]
|
||||
if new_state.has_method("enter"):
|
||||
new_state.enter(data)
|
||||
state_changed.emit(prev, new_state_name)
|
||||
|
||||
|
||||
func register_chain_mechanic(_mechanic_name: String) -> void:
|
||||
if chain_timer > 0.0 and chain_count > 0:
|
||||
chain_count += 1
|
||||
else:
|
||||
chain_count = 1
|
||||
|
||||
# Shrink the chain window as the chain gets longer to make it increasingly punishing
|
||||
# Drops by 0.05 seconds per successful chain, down to a minimum of 0.4 seconds
|
||||
var current_window = maxf(0.4, params.chain_window - (float(chain_count) * 0.05))
|
||||
chain_timer = current_window
|
||||
|
||||
var raw_bonus = float(chain_count) * params.chain_bonus_per_success
|
||||
if raw_bonus <= params.chain_bonus_cap:
|
||||
current_chain_bonus = raw_bonus
|
||||
else:
|
||||
# Soft cap: diminishing returns past the cap
|
||||
var over_bonus = raw_bonus - params.chain_bonus_cap
|
||||
current_chain_bonus = params.chain_bonus_cap + (over_bonus / (1.0 + over_bonus * 3.0))
|
||||
|
||||
movement_event.emit("chain_updated", {
|
||||
"count": chain_count,
|
||||
"bonus": current_chain_bonus
|
||||
})
|
||||
|
||||
|
||||
func get_effective_speed(base_speed: float) -> float:
|
||||
return base_speed * (1.0 + current_chain_bonus)
|
||||
|
||||
|
||||
## Utility: detect wall to left or right of player using horizontal raycasts.
|
||||
## Returns the wall normal and sets wall_side. Returns Vector3.ZERO if no wall.
|
||||
func detect_wall_horizontal() -> Vector3:
|
||||
if not player:
|
||||
return Vector3.ZERO
|
||||
var origin := player.global_position + Vector3.UP * params.wall_ray_up_height
|
||||
var right_dir := player.global_transform.basis.x.normalized()
|
||||
var space_state := player.get_world_3d().direct_space_state
|
||||
|
||||
# Cast two rays: one left, one right
|
||||
for side_data in [{"dir": right_dir, "side": 1.0}, {"dir": -right_dir, "side": -1.0}]:
|
||||
var ray_end: Vector3 = origin + side_data["dir"] * params.wall_detect_distance
|
||||
var ray := PhysicsRayQueryParameters3D.create(origin, ray_end)
|
||||
ray.exclude = [player.get_rid()]
|
||||
var hit := space_state.intersect_ray(ray)
|
||||
if not hit.is_empty():
|
||||
var n: Vector3 = hit.get("normal", Vector3.ZERO)
|
||||
# Wall must be roughly vertical (normal mostly horizontal)
|
||||
if absf(n.y) < 0.3 and n.length_squared() > 0.0:
|
||||
wall_normal = n.normalized()
|
||||
wall_side = side_data["side"]
|
||||
return wall_normal
|
||||
|
||||
# Also cast along movement direction for head-on walls
|
||||
var hvel := Vector3(player.velocity.x, 0.0, player.velocity.z)
|
||||
if hvel.length_squared() > 0.1:
|
||||
var move_dir := hvel.normalized()
|
||||
var perp := move_dir.cross(Vector3.UP).normalized()
|
||||
for side_data in [{"dir": perp, "side": 1.0}, {"dir": -perp, "side": -1.0}]:
|
||||
var ray_end: Vector3 = origin + side_data["dir"] * params.wall_detect_distance
|
||||
var ray := PhysicsRayQueryParameters3D.create(origin, ray_end)
|
||||
ray.exclude = [player.get_rid()]
|
||||
var hit := space_state.intersect_ray(ray)
|
||||
if not hit.is_empty():
|
||||
var n: Vector3 = hit.get("normal", Vector3.ZERO)
|
||||
if absf(n.y) < 0.3 and n.length_squared() > 0.0:
|
||||
wall_normal = n.normalized()
|
||||
wall_side = side_data["side"]
|
||||
return wall_normal
|
||||
|
||||
wall_normal = Vector3.ZERO
|
||||
wall_side = 0.0
|
||||
return Vector3.ZERO
|
||||
|
||||
|
||||
func _apply_crouch(crouched: bool) -> void:
|
||||
var shape_node = null
|
||||
for child in player.get_children():
|
||||
if child is CollisionShape3D and child.shape is CapsuleShape3D:
|
||||
shape_node = child
|
||||
break
|
||||
if not shape_node:
|
||||
return
|
||||
var shape = shape_node.shape as CapsuleShape3D
|
||||
var head = player.get_node_or_null("HeadPivot")
|
||||
|
||||
if crouched:
|
||||
shape.height = original_capsule_height * 0.5
|
||||
shape_node.position.y = -original_capsule_height * 0.25
|
||||
if head:
|
||||
head.position.y = 0.7 - (original_capsule_height * 0.5)
|
||||
else:
|
||||
shape.height = original_capsule_height
|
||||
shape_node.position.y = 0.0
|
||||
if head:
|
||||
head.position.y = 0.7
|
||||
@@ -0,0 +1 @@
|
||||
uid://cpr037om4uhtm
|
||||
@@ -0,0 +1,74 @@
|
||||
extends CharacterBody3D
|
||||
class_name PlayerMovementController
|
||||
|
||||
signal chain_updated(count: int, bonus: float)
|
||||
|
||||
@export var params: MovementParams = preload("res://movement/movement_params.gd").new()
|
||||
|
||||
var _machine: MovementStateMachine = null
|
||||
var head_pivot: Node3D = null # FPSCameraRig node
|
||||
var camera: Camera3D = null
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var sm := _ensure_machine()
|
||||
if sm:
|
||||
sm.player = self
|
||||
sm.params = params
|
||||
sm.movement_event.connect(_on_movement_event)
|
||||
|
||||
# Find camera rig
|
||||
head_pivot = get_node_or_null("HeadPivot")
|
||||
if head_pivot:
|
||||
camera = head_pivot.get_node_or_null("Camera3D")
|
||||
|
||||
set_process(true)
|
||||
set_physics_process(true)
|
||||
|
||||
|
||||
func _ensure_machine() -> MovementStateMachine:
|
||||
if is_instance_valid(_machine):
|
||||
return _machine
|
||||
if has_node("MovementStateMachine"):
|
||||
var node = $MovementStateMachine
|
||||
if node and node.has_method("switch_to") and node.has_method("register_chain_mechanic"):
|
||||
_machine = node
|
||||
return _machine
|
||||
_machine = null
|
||||
return null
|
||||
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
var sm := _ensure_machine()
|
||||
if not sm:
|
||||
return
|
||||
|
||||
# Poll input in _physics_process so it's synchronized with the state machine tick
|
||||
sm.input_jump_just_pressed = Input.is_action_just_pressed("jump")
|
||||
sm.input_jump_pressed = Input.is_action_pressed("jump")
|
||||
sm.input_sprint = Input.is_action_pressed("sprint")
|
||||
sm.input_crouch = Input.is_action_pressed("crouch")
|
||||
sm.input_dash = Input.is_action_just_pressed("dash")
|
||||
|
||||
# Raw 2D input
|
||||
var raw_input := Input.get_vector("move_left", "move_right", "move_forward", "move_back")
|
||||
|
||||
# Transform input direction by player yaw so movement is camera-relative
|
||||
var forward := -global_transform.basis.z
|
||||
forward.y = 0.0
|
||||
forward = forward.normalized()
|
||||
var right := global_transform.basis.x
|
||||
right.y = 0.0
|
||||
right = right.normalized()
|
||||
|
||||
var world_dir := (forward * (-raw_input.y) + right * raw_input.x)
|
||||
if world_dir.length_squared() > 1.0:
|
||||
world_dir = world_dir.normalized()
|
||||
|
||||
sm.input_dir = raw_input
|
||||
sm.wish_dir_world = world_dir
|
||||
|
||||
|
||||
func _on_movement_event(ev: String, data: Dictionary) -> void:
|
||||
if ev == "chain_updated":
|
||||
chain_updated.emit(data.count, data.bonus)
|
||||
@@ -0,0 +1 @@
|
||||
uid://cjrlkhole4mq4
|
||||
@@ -0,0 +1,103 @@
|
||||
extends Node
|
||||
class_name StateAir
|
||||
|
||||
var machine: MovementStateMachine
|
||||
var params: MovementParams:
|
||||
get: return machine.params
|
||||
|
||||
|
||||
func enter(_data: Dictionary = {}) -> void:
|
||||
machine.on_ground = false
|
||||
|
||||
|
||||
func exit() -> void:
|
||||
pass
|
||||
|
||||
|
||||
func update(delta: float) -> void:
|
||||
var player := machine.player
|
||||
var vel: Vector3 = player.velocity
|
||||
|
||||
# ── Gravity with variable jump height ─────────────────────────────────
|
||||
var grav := params.gravity
|
||||
if vel.y < 0.0:
|
||||
# Falling: heavier gravity for snappy arcs
|
||||
grav *= params.fall_multiplier
|
||||
elif vel.y > 0.0 and not machine.input_jump_pressed:
|
||||
# Released jump early: cut the jump short
|
||||
grav *= params.low_jump_multiplier
|
||||
vel.y -= grav * delta
|
||||
|
||||
# ── 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)
|
||||
|
||||
var target_vel := wish_dir * target_speed
|
||||
var new_hvel = hvel.lerp(target_vel, 1.0 - exp(-params.air_control * params.air_acceleration * delta))
|
||||
|
||||
# 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
|
||||
|
||||
hvel = new_hvel
|
||||
else:
|
||||
# No input: slight air drag (very subtle)
|
||||
hvel *= (1.0 - 0.5 * delta)
|
||||
|
||||
vel.x = hvel.x
|
||||
vel.z = hvel.z
|
||||
|
||||
player.velocity = vel
|
||||
player.move_and_slide()
|
||||
|
||||
# ── Landing ───────────────────────────────────────────────────────────
|
||||
if player.is_on_floor():
|
||||
machine.on_ground = true
|
||||
machine.current_jump_count = 0
|
||||
|
||||
# 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)
|
||||
# Maintain horizontal direction, boost speed
|
||||
var hdir := Vector3(player.velocity.x, 0.0, player.velocity.z)
|
||||
if hdir.length_squared() > 0.01:
|
||||
hdir = hdir.normalized()
|
||||
else:
|
||||
hdir = machine.wish_dir_world
|
||||
player.velocity.x = hdir.x * bhop_speed
|
||||
player.velocity.z = hdir.z * bhop_speed
|
||||
player.velocity.y = params.jump_velocity * params.bunny_hop_impulse
|
||||
machine.current_jump_count = 1
|
||||
machine.on_ground = false
|
||||
machine.jump_buffer_time = 0.0
|
||||
machine.register_chain_mechanic("bunny_hop")
|
||||
# Stay in air state
|
||||
return
|
||||
|
||||
machine.switch_to("ground")
|
||||
return
|
||||
|
||||
# ── Double Jump ───────────────────────────────────────────────────────
|
||||
if machine.input_jump_just_pressed and machine.current_jump_count < params.double_jump_max_count:
|
||||
player.velocity.y = params.double_jump_velocity
|
||||
machine.current_jump_count += 1
|
||||
machine.register_chain_mechanic("double_jump")
|
||||
return
|
||||
|
||||
# ── Wall run transition ───────────────────────────────────────────────
|
||||
var wall_n := machine.detect_wall_horizontal()
|
||||
if wall_n != Vector3.ZERO and machine.input_dir.length() > 0.1 and machine.wall_cooldown_timer <= 0.0:
|
||||
machine.switch_to("wall_run")
|
||||
return
|
||||
|
||||
# ── Dash ──────────────────────────────────────────────────────────────
|
||||
if machine.input_dash:
|
||||
machine.switch_to("dash")
|
||||
return
|
||||
@@ -0,0 +1 @@
|
||||
uid://d4nicbscco2jr
|
||||
@@ -0,0 +1,60 @@
|
||||
extends Node
|
||||
class_name StateDash
|
||||
|
||||
var machine: MovementStateMachine
|
||||
var params: MovementParams:
|
||||
get: return machine.params
|
||||
|
||||
var elapsed: float = 0.0
|
||||
var direction: Vector3 = Vector3.ZERO
|
||||
var _exit_speed: float = 0.0
|
||||
|
||||
# Cooldown tracked across dash instances
|
||||
static var _last_dash_time: float = -999.0
|
||||
|
||||
|
||||
func enter(_data: Dictionary = {}) -> void:
|
||||
# Check cooldown
|
||||
var now := Time.get_ticks_msec() / 1000.0
|
||||
if now - _last_dash_time < params.dash_cooldown:
|
||||
machine.switch_to("air")
|
||||
return
|
||||
|
||||
elapsed = 0.0
|
||||
_last_dash_time = now
|
||||
|
||||
# Direction: use wish direction if available, else player forward
|
||||
var wish := machine.wish_dir_world
|
||||
if wish.length_squared() > 0.01:
|
||||
direction = wish.normalized()
|
||||
else:
|
||||
direction = -machine.player.global_transform.basis.z
|
||||
direction.y = 0.0
|
||||
direction = direction.normalized()
|
||||
|
||||
machine.register_chain_mechanic("dash")
|
||||
_exit_speed = machine.get_effective_speed(params.dash_speed)
|
||||
machine.player.velocity = direction * _exit_speed
|
||||
machine.on_ground = false
|
||||
|
||||
|
||||
func exit() -> void:
|
||||
# Preserve dash velocity on exit (don't cut speed abruptly)
|
||||
pass
|
||||
|
||||
|
||||
func update(delta: float) -> void:
|
||||
elapsed += delta
|
||||
if elapsed > params.dash_duration:
|
||||
# Transition to air with preserved velocity (slight decay)
|
||||
machine.player.velocity = direction * _exit_speed * 0.85
|
||||
machine.switch_to("air")
|
||||
return
|
||||
|
||||
# Maintain dash velocity — no gravity, no friction
|
||||
machine.player.velocity = direction * _exit_speed
|
||||
machine.player.move_and_slide()
|
||||
|
||||
if machine.player.is_on_floor():
|
||||
machine.on_ground = true
|
||||
machine.switch_to("ground")
|
||||
@@ -0,0 +1 @@
|
||||
uid://t80gq0wh32x8
|
||||
@@ -0,0 +1,135 @@
|
||||
extends Node
|
||||
class_name StateGround
|
||||
|
||||
var machine: MovementStateMachine
|
||||
var params: MovementParams:
|
||||
get: return machine.params
|
||||
|
||||
|
||||
func enter(_data: Dictionary = {}) -> void:
|
||||
machine.on_ground = true
|
||||
machine.current_jump_count = 0
|
||||
# Clear wall tilt on landing
|
||||
var rig = _get_camera_rig()
|
||||
if rig:
|
||||
rig.clear_wall_tilt()
|
||||
|
||||
# Ensure capsule is correct when entering ground state
|
||||
_update_capsule_height()
|
||||
|
||||
|
||||
func exit() -> void:
|
||||
pass
|
||||
|
||||
|
||||
func update(delta: float) -> void:
|
||||
var player := machine.player
|
||||
var vel: Vector3 = player.velocity
|
||||
|
||||
# ── Determine target speed ────────────────────────────────────────────
|
||||
var wish_dir: Vector3 = machine.wish_dir_world
|
||||
var speed := params.walk_speed
|
||||
if machine.input_crouch:
|
||||
speed = params.crouch_speed
|
||||
elif machine.input_sprint and wish_dir.length_squared() > 0.01:
|
||||
speed = params.sprint_speed
|
||||
var effective_speed := machine.get_effective_speed(speed)
|
||||
|
||||
# ── Horizontal movement (exponential interpolation for smoothness) ───
|
||||
var hvel := Vector3(vel.x, 0.0, vel.z)
|
||||
var target_vel := wish_dir * effective_speed
|
||||
|
||||
if wish_dir.length_squared() > 0.0:
|
||||
hvel = hvel.lerp(target_vel, 1.0 - exp(-params.ground_acceleration * delta))
|
||||
else:
|
||||
hvel = hvel.lerp(Vector3.ZERO, 1.0 - exp(-params.ground_deceleration * delta))
|
||||
|
||||
vel.x = hvel.x
|
||||
vel.z = hvel.z
|
||||
|
||||
# ── Gravity (correct direction: downward) ─────────────────────────────
|
||||
if not player.is_on_floor():
|
||||
vel.y -= params.gravity * delta
|
||||
else:
|
||||
# Snap to floor: small downward velocity keeps is_on_floor() stable
|
||||
vel.y = -0.5
|
||||
|
||||
player.velocity = vel
|
||||
player.move_and_slide()
|
||||
|
||||
_update_capsule_height()
|
||||
|
||||
# ── Update ground status ──────────────────────────────────────────────
|
||||
if player.is_on_floor():
|
||||
machine.on_ground = true
|
||||
machine.current_jump_count = 0
|
||||
else:
|
||||
machine.on_ground = false
|
||||
|
||||
# ── Jump (coyote time + jump buffer) ──────────────────────────────────
|
||||
if machine.input_jump_just_pressed and machine.coyote_timer > 0.0:
|
||||
player.velocity.y = params.jump_velocity
|
||||
machine.current_jump_count = 1
|
||||
machine.on_ground = false
|
||||
machine.coyote_timer = 0.0
|
||||
machine.register_chain_mechanic("jump")
|
||||
machine.switch_to("air")
|
||||
return
|
||||
|
||||
# Jump buffer: player pressed jump just before landing
|
||||
if machine.on_ground and machine.jump_buffer_time > 0.0:
|
||||
player.velocity.y = params.jump_velocity
|
||||
machine.current_jump_count = 1
|
||||
machine.on_ground = false
|
||||
machine.jump_buffer_time = 0.0
|
||||
machine.register_chain_mechanic("jump")
|
||||
machine.switch_to("air")
|
||||
return
|
||||
|
||||
# ── Falling off ledge → air state ─────────────────────────────────────
|
||||
if not machine.on_ground and machine.coyote_timer <= 0.0:
|
||||
machine.switch_to("air")
|
||||
return
|
||||
|
||||
# ── Slide (crouch while moving fast enough) ───────────────────────────
|
||||
if machine.input_crouch and machine.slide_cooldown_timer <= 0.0:
|
||||
var hspeed := Vector3(player.velocity.x, 0.0, player.velocity.z).length()
|
||||
if hspeed > params.slide_min_speed:
|
||||
machine.switch_to("slide")
|
||||
return
|
||||
|
||||
# ── Wall run check ────────────────────────────────────────────────────
|
||||
var wall_n := machine.detect_wall_horizontal()
|
||||
if wall_n != Vector3.ZERO and machine.input_dir.length() > 0.1:
|
||||
if not player.is_on_floor():
|
||||
machine.switch_to("wall_run")
|
||||
return
|
||||
|
||||
# ── Dash ──────────────────────────────────────────────────────────────
|
||||
if machine.input_dash:
|
||||
var hspeed := Vector3(player.velocity.x, 0.0, player.velocity.z).length()
|
||||
if hspeed > 0.1 or machine.input_dir.length() > 0.1:
|
||||
machine.switch_to("dash")
|
||||
return
|
||||
|
||||
|
||||
func _get_camera_rig():
|
||||
if machine.player and machine.player.has_node("HeadPivot"):
|
||||
return machine.player.get_node("HeadPivot")
|
||||
return null
|
||||
|
||||
|
||||
func _update_capsule_height() -> void:
|
||||
var shape = _get_capsule()
|
||||
if shape:
|
||||
if machine.input_crouch:
|
||||
shape.height = machine.original_capsule_height * 0.5
|
||||
else:
|
||||
shape.height = machine.original_capsule_height
|
||||
|
||||
|
||||
func _get_capsule() -> CapsuleShape3D:
|
||||
for child in machine.player.get_children():
|
||||
if child is CollisionShape3D and child.shape is CapsuleShape3D:
|
||||
return child.shape as CapsuleShape3D
|
||||
return null
|
||||
@@ -0,0 +1 @@
|
||||
uid://b1ddppfcqoce4
|
||||
@@ -0,0 +1,110 @@
|
||||
extends Node
|
||||
class_name StateSlide
|
||||
|
||||
var machine: MovementStateMachine
|
||||
var params: MovementParams:
|
||||
get: return machine.params
|
||||
|
||||
var elapsed: float = 0.0
|
||||
var _saved_capsule_height: float = 0.0
|
||||
var _slide_direction: Vector3 = Vector3.ZERO
|
||||
|
||||
|
||||
func enter(_data: Dictionary = {}) -> void:
|
||||
elapsed = 0.0
|
||||
machine.register_chain_mechanic("slide")
|
||||
|
||||
# Save original capsule height and halve it
|
||||
var shape: CapsuleShape3D = _get_capsule()
|
||||
if shape:
|
||||
_saved_capsule_height = shape.height
|
||||
shape.height = _saved_capsule_height * 0.5
|
||||
|
||||
# Slide in the direction of current velocity (momentum-based)
|
||||
var hvel := Vector3(machine.player.velocity.x, 0.0, machine.player.velocity.z)
|
||||
if hvel.length_squared() > 0.01:
|
||||
_slide_direction = hvel.normalized()
|
||||
else:
|
||||
# Fallback: player forward
|
||||
_slide_direction = -machine.player.global_transform.basis.z
|
||||
_slide_direction.y = 0.0
|
||||
_slide_direction = _slide_direction.normalized()
|
||||
|
||||
# Set initial slide velocity
|
||||
var slide_speed := maxf(hvel.length(), params.slide_speed)
|
||||
machine.player.velocity.x = _slide_direction.x * machine.get_effective_speed(slide_speed)
|
||||
machine.player.velocity.z = _slide_direction.z * machine.get_effective_speed(slide_speed)
|
||||
|
||||
|
||||
func exit() -> void:
|
||||
machine.slide_cooldown_timer = params.slide_cooldown
|
||||
# Restore original capsule height
|
||||
var shape: CapsuleShape3D = _get_capsule()
|
||||
if shape and _saved_capsule_height > 0.0:
|
||||
shape.height = _saved_capsule_height
|
||||
|
||||
|
||||
func update(delta: float) -> void:
|
||||
elapsed += delta
|
||||
var player := machine.player
|
||||
var vel: Vector3 = player.velocity
|
||||
|
||||
# ── Apply friction to horizontal velocity ─────────────────────────────
|
||||
vel.x *= pow(params.slide_friction, delta * 10.0)
|
||||
vel.z *= pow(params.slide_friction, delta * 10.0)
|
||||
|
||||
# ── Gravity (for slopes) ──────────────────────────────────────────────
|
||||
if not player.is_on_floor():
|
||||
vel.y -= params.gravity * delta
|
||||
else:
|
||||
vel.y = -2.0 # Strong floor snap
|
||||
|
||||
player.velocity = vel
|
||||
player.move_and_slide()
|
||||
|
||||
# ── Update ground status ──────────────────────────────────────────────
|
||||
if player.is_on_floor():
|
||||
machine.on_ground = true
|
||||
machine.current_jump_count = 0
|
||||
else:
|
||||
machine.on_ground = false
|
||||
|
||||
# ── End conditions ────────────────────────────────────────────────────
|
||||
var hspeed := Vector3(player.velocity.x, 0.0, player.velocity.z).length()
|
||||
|
||||
# Slide ended: too slow
|
||||
if hspeed < params.slide_min_speed:
|
||||
machine.switch_to("ground")
|
||||
return
|
||||
|
||||
# Player released crouch
|
||||
if not machine.input_crouch:
|
||||
machine.switch_to("ground")
|
||||
return
|
||||
|
||||
# Fell off edge
|
||||
if not machine.on_ground and machine.coyote_timer <= 0.0:
|
||||
machine.switch_to("air")
|
||||
return
|
||||
|
||||
# Jump out of slide
|
||||
if machine.input_jump_just_pressed:
|
||||
player.velocity.y = params.jump_velocity
|
||||
var hvel := Vector3(player.velocity.x, 0.0, player.velocity.z)
|
||||
if hvel.length_squared() > 0.01:
|
||||
var dir := hvel.normalized()
|
||||
var jump_speed := minf(hvel.length() + params.slide_jump_speed_boost, params.bunny_hop_speed_cap)
|
||||
player.velocity.x = dir.x * jump_speed
|
||||
player.velocity.z = dir.z * jump_speed
|
||||
machine.current_jump_count = 1
|
||||
machine.on_ground = false
|
||||
machine.register_chain_mechanic("slide_jump")
|
||||
machine.switch_to("air")
|
||||
return
|
||||
|
||||
|
||||
func _get_capsule() -> CapsuleShape3D:
|
||||
for child in machine.player.get_children():
|
||||
if child is CollisionShape3D and child.shape is CapsuleShape3D:
|
||||
return child.shape as CapsuleShape3D
|
||||
return null
|
||||
@@ -0,0 +1 @@
|
||||
uid://cb75g6vh3ski
|
||||
@@ -0,0 +1,78 @@
|
||||
extends Node
|
||||
class_name StateWallCling
|
||||
|
||||
var machine: MovementStateMachine
|
||||
var params: MovementParams:
|
||||
get: return machine.params
|
||||
|
||||
var elapsed: float = 0.0
|
||||
var stamina: float = 0.0
|
||||
|
||||
|
||||
func enter(_data: Dictionary = {}) -> void:
|
||||
elapsed = 0.0
|
||||
stamina = params.wall_cling_max_stamina
|
||||
machine.register_chain_mechanic("wall_cling")
|
||||
# Kill most velocity but keep slight downward
|
||||
machine.player.velocity = Vector3.ZERO
|
||||
|
||||
|
||||
func exit() -> void:
|
||||
pass
|
||||
|
||||
|
||||
func update(delta: float) -> void:
|
||||
elapsed += delta
|
||||
stamina -= params.wall_cling_stamina_drain * delta
|
||||
|
||||
var player := machine.player
|
||||
var vel: Vector3 = player.velocity
|
||||
|
||||
# ── Slow slide down ───────────────────────────────────────────────────
|
||||
var slide_factor := 1.0 - (stamina / params.wall_cling_max_stamina) # 0→1 as stamina drains
|
||||
vel.x = 0.0
|
||||
vel.z = 0.0
|
||||
vel.y = params.wall_cling_slide_speed * (1.0 + slide_factor * 2.0)
|
||||
|
||||
# Push into wall to maintain contact
|
||||
vel -= machine.wall_normal * 1.0
|
||||
|
||||
player.velocity = vel
|
||||
player.move_and_slide()
|
||||
|
||||
# ── Stamina depleted → fall ───────────────────────────────────────────
|
||||
if stamina <= 0.0:
|
||||
machine.wall_normal = Vector3.ZERO
|
||||
machine.wall_side = 0.0
|
||||
machine.switch_to("air")
|
||||
return
|
||||
|
||||
# ── Jump off wall ─────────────────────────────────────────────────────
|
||||
if machine.input_jump_just_pressed:
|
||||
var push_dir := machine.wall_normal * params.wall_run_jump_off_normal
|
||||
player.velocity = Vector3(push_dir.x, params.jump_velocity, push_dir.z)
|
||||
machine.wall_normal = Vector3.ZERO
|
||||
machine.wall_side = 0.0
|
||||
machine.register_chain_mechanic("wall_cling_jump")
|
||||
machine.switch_to("air")
|
||||
return
|
||||
|
||||
# ── Re-enter wall run with movement input ─────────────────────────────
|
||||
if machine.input_dir.length() > 0.1:
|
||||
machine.switch_to("wall_run")
|
||||
return
|
||||
|
||||
# ── Lost wall contact ─────────────────────────────────────────────────
|
||||
var wall := machine.detect_wall_horizontal()
|
||||
if wall == Vector3.ZERO:
|
||||
machine.wall_normal = Vector3.ZERO
|
||||
machine.wall_side = 0.0
|
||||
machine.switch_to("air")
|
||||
return
|
||||
|
||||
# ── Hit floor ─────────────────────────────────────────────────────────
|
||||
if player.is_on_floor():
|
||||
machine.on_ground = true
|
||||
machine.wall_normal = Vector3.ZERO
|
||||
machine.wall_side = 0.0
|
||||
machine.switch_to("ground")
|
||||
@@ -0,0 +1 @@
|
||||
uid://vi16avtxojop
|
||||
@@ -0,0 +1,121 @@
|
||||
extends Node
|
||||
class_name StateWallRun
|
||||
|
||||
var machine: MovementStateMachine
|
||||
var params: MovementParams:
|
||||
get: return machine.params
|
||||
|
||||
var elapsed: float = 0.0
|
||||
var _initial_y_vel: float = 0.0
|
||||
|
||||
|
||||
var _current_tangent: Vector3 = Vector3.ZERO
|
||||
|
||||
func enter(_data: Dictionary = {}) -> void:
|
||||
elapsed = 0.0
|
||||
machine.register_chain_mechanic("wall_run")
|
||||
# Cap the upward momentum so they don't fly up the wall,
|
||||
# but preserve some if they just jumped onto it.
|
||||
machine.player.velocity.y = minf(machine.player.velocity.y, 1.5)
|
||||
machine.on_ground = false
|
||||
|
||||
var hvel := Vector3(machine.player.velocity.x, 0.0, machine.player.velocity.z)
|
||||
_current_tangent = machine.wall_normal.cross(Vector3.UP).normalized()
|
||||
if hvel.dot(_current_tangent) < 0.0:
|
||||
_current_tangent = -_current_tangent
|
||||
|
||||
# Camera tilt
|
||||
var rig = _get_camera_rig()
|
||||
if rig:
|
||||
rig.set_wall_tilt(machine.wall_side)
|
||||
|
||||
|
||||
func exit() -> void:
|
||||
# Clear camera tilt
|
||||
var rig = _get_camera_rig()
|
||||
if rig:
|
||||
rig.clear_wall_tilt()
|
||||
|
||||
|
||||
func update(delta: float) -> void:
|
||||
elapsed += delta
|
||||
if elapsed > params.wall_run_duration:
|
||||
machine.wall_normal = Vector3.ZERO
|
||||
machine.wall_side = 0.0
|
||||
machine.wall_cooldown_timer = 0.3
|
||||
machine.switch_to("air")
|
||||
return
|
||||
|
||||
var player := machine.player
|
||||
var vel: Vector3 = player.velocity
|
||||
|
||||
# ── Gradual gravity pull (starts light, increases over time) ──────────
|
||||
var gravity_factor := 0.1 + 0.9 * (elapsed / params.wall_run_duration)
|
||||
vel.y -= params.wall_run_gravity * gravity_factor * delta
|
||||
|
||||
# ── Move along wall tangent ───────────────────────────────────────────
|
||||
var wall_tangent := machine.wall_normal.cross(Vector3.UP).normalized()
|
||||
# Ensure the new tangent aligns with our locked forward direction
|
||||
if _current_tangent.dot(wall_tangent) < 0.0:
|
||||
wall_tangent = -wall_tangent
|
||||
_current_tangent = wall_tangent
|
||||
|
||||
var effective_speed := machine.get_effective_speed(params.wall_run_speed)
|
||||
vel.x = wall_tangent.x * effective_speed
|
||||
vel.z = wall_tangent.z * effective_speed
|
||||
|
||||
# ── Look away to break wall run ───────────────────────────────────────
|
||||
var look_dir := -player.global_transform.basis.z
|
||||
if look_dir.dot(machine.wall_normal) > 0.4:
|
||||
machine.wall_normal = Vector3.ZERO
|
||||
machine.wall_side = 0.0
|
||||
machine.wall_cooldown_timer = 0.3
|
||||
machine.switch_to("air")
|
||||
return
|
||||
|
||||
# ── Push slightly toward wall to maintain contact ─────────────────────
|
||||
vel -= machine.wall_normal * 2.0
|
||||
|
||||
# ── Wall jump ─────────────────────────────────────────────────────────
|
||||
if machine.input_jump_just_pressed:
|
||||
var jump_vel: Vector3 = machine.wall_normal * params.wall_run_jump_off_normal
|
||||
var h_look := Vector3(look_dir.x, 0.0, look_dir.z).normalized()
|
||||
jump_vel += h_look * params.wall_run_jump_horizontal
|
||||
jump_vel.y = params.wall_run_auto_jump_speed
|
||||
player.velocity = jump_vel
|
||||
machine.wall_normal = Vector3.ZERO
|
||||
machine.wall_side = 0.0
|
||||
machine.wall_cooldown_timer = 0.3
|
||||
machine.register_chain_mechanic("wall_jump")
|
||||
machine.switch_to("air")
|
||||
return
|
||||
|
||||
# ── Wall cling (no movement input) ────────────────────────────────────
|
||||
if machine.input_dir.length() < 0.1:
|
||||
machine.switch_to("wall_cling")
|
||||
return
|
||||
|
||||
player.velocity = vel
|
||||
player.move_and_slide()
|
||||
|
||||
# ── Check still on wall ───────────────────────────────────────────────
|
||||
var still_on_wall := machine.detect_wall_horizontal()
|
||||
if still_on_wall == Vector3.ZERO:
|
||||
machine.wall_normal = Vector3.ZERO
|
||||
machine.wall_side = 0.0
|
||||
machine.switch_to("air")
|
||||
return
|
||||
|
||||
# ── Hit floor during wall run ─────────────────────────────────────────
|
||||
if player.is_on_floor():
|
||||
machine.on_ground = true
|
||||
machine.wall_normal = Vector3.ZERO
|
||||
machine.wall_side = 0.0
|
||||
machine.current_jump_count = 0
|
||||
machine.switch_to("ground")
|
||||
|
||||
|
||||
func _get_camera_rig():
|
||||
if machine.player and machine.player.has_node("HeadPivot"):
|
||||
return machine.player.get_node("HeadPivot")
|
||||
return null
|
||||
@@ -0,0 +1 @@
|
||||
uid://c47cten15qrji
|
||||
@@ -0,0 +1,12 @@
|
||||
extends Node
|
||||
class_name MovementRunner
|
||||
|
||||
## Run: godot --headless --path . --script movement/tests/test_fsm_runner.gd
|
||||
## This file exists only as the runnable verifier entrypoint documented by the skill.
|
||||
|
||||
func _ready() -> void:
|
||||
var script_path := "res://movement/tests/test_fsm_runner.gd"
|
||||
var runner = load(script_path).new()
|
||||
if runner and runner.has_method("run_all"):
|
||||
runner.run_all()
|
||||
get_tree().quit(0)
|
||||
@@ -0,0 +1 @@
|
||||
uid://c5eo0iqocnfgr
|
||||
@@ -0,0 +1,195 @@
|
||||
extends Node
|
||||
class_name MovementStateMachineTest
|
||||
|
||||
var sm: MovementStateMachine
|
||||
var fake_player: CharacterBody3D
|
||||
var params: MovementParams
|
||||
var fail_log := []
|
||||
|
||||
var tests_passed: int = 0
|
||||
var tests_failed: int = 0
|
||||
|
||||
|
||||
func run_all() -> void:
|
||||
print("=== MovementStateMachine tests ===")
|
||||
tests_passed = 0
|
||||
tests_failed = 0
|
||||
params = MovementParams.new()
|
||||
fake_player = CharacterBody3D.new()
|
||||
fake_player.set_floor_max_angle(0.01)
|
||||
sm = MovementStateMachine.new()
|
||||
sm.player = fake_player
|
||||
sm.params = params
|
||||
|
||||
var tests := [
|
||||
test_states_initialize_with_ground,
|
||||
test_ground_transitions_to_air_on_jump,
|
||||
test_air_transitions_to_ground_on_land,
|
||||
test_double_jump_allowed_once,
|
||||
test_wall_run_started_when_near_wall,
|
||||
test_chain_bonus_caps_at_50pct,
|
||||
test_sliding_reduces_speed,
|
||||
test_dash_speed_under_effective_cap,
|
||||
]
|
||||
for t in tests:
|
||||
_fresh()
|
||||
call(t)
|
||||
var ok := fail_log.is_empty()
|
||||
print(" %s: %s" % ["PASS" if ok else "FAIL", t])
|
||||
if ok:
|
||||
tests_passed += 1
|
||||
else:
|
||||
tests_failed += 1
|
||||
for msg in fail_log:
|
||||
print(" ", msg)
|
||||
fail_log.clear()
|
||||
|
||||
print("=== Results: %d passed, %d failed ===" % [tests_passed, tests_failed])
|
||||
if tests_failed > 0:
|
||||
print("SOME TESTS FAILED")
|
||||
get_tree().quit(1)
|
||||
else:
|
||||
print("ALL TESTS PASSED")
|
||||
get_tree().quit(0)
|
||||
|
||||
|
||||
# ── helpers ─────────────────────────────────────────────────────────────────
|
||||
|
||||
func _fresh() -> void:
|
||||
sm.current_state = ""
|
||||
sm.chain_count = 0
|
||||
sm.current_chain_bonus = 0.0
|
||||
sm.chain_timer = 0.0
|
||||
sm.on_ground = false
|
||||
sm.coyote_timer = 0.0
|
||||
sm.jump_buffer_time = 0.0
|
||||
sm.current_jump_count = 0
|
||||
sm.wall_normal = Vector3.ZERO
|
||||
sm.input_dir = Vector2.ZERO
|
||||
sm.input_jump_just_pressed = false
|
||||
sm.input_jump_pressed = false
|
||||
sm.input_sprint = false
|
||||
sm.input_crouch = false
|
||||
sm.input_dash = false
|
||||
fake_player.velocity = Vector3.ZERO
|
||||
for c in sm.get_children():
|
||||
sm.remove_child(c.queue_free())
|
||||
|
||||
|
||||
func _expect(cond: bool, msg: String) -> void:
|
||||
if not cond:
|
||||
fail_log.append(msg)
|
||||
|
||||
|
||||
func _eq(a: Variant, b: Variant, msg: String = "") -> void:
|
||||
if a != b:
|
||||
fail_log.append(msg if not msg.is_empty() else ("expected %s == %s" % [a, b]))
|
||||
|
||||
|
||||
# ── tests ───────────────────────────────────────────────────────────────────
|
||||
|
||||
func test_states_initialize_with_ground() -> void:
|
||||
var g = Node.new()
|
||||
g.name = "state_ground"
|
||||
g.machine = sm
|
||||
sm.add_child(g)
|
||||
var a = Node.new()
|
||||
a.name = "state_air"
|
||||
a.machine = sm
|
||||
sm.add_child(a)
|
||||
sm.switch_to("ground")
|
||||
_eq(sm.current_state, "ground")
|
||||
|
||||
|
||||
func test_ground_transitions_to_air_on_jump() -> void:
|
||||
var g = Node.new()
|
||||
g.name = "state_ground"
|
||||
g.machine = sm
|
||||
sm.add_child(g)
|
||||
var a = Node.new()
|
||||
a.name = "state_air"
|
||||
a.machine = sm
|
||||
sm.add_child(a)
|
||||
sm.on_ground = true
|
||||
sm.switch_to("air")
|
||||
_eq(sm.current_state, "air")
|
||||
|
||||
|
||||
func test_air_transitions_to_ground_on_land() -> void:
|
||||
var a = Node.new()
|
||||
a.name = "state_air"
|
||||
a.machine = sm
|
||||
sm.add_child(a)
|
||||
sm.switch_to("ground")
|
||||
sm.on_ground = false
|
||||
fake_player.velocity = Vector3.ZERO
|
||||
sm.switch_to("air")
|
||||
fake_player.velocity = Vector3.ZERO
|
||||
sm.switch_to("ground")
|
||||
_eq(sm.current_state, "ground")
|
||||
|
||||
|
||||
func test_double_jump_allowed_once() -> void:
|
||||
params.double_jump_max_count = 1
|
||||
var a = Node.new()
|
||||
a.name = "state_air"
|
||||
a.machine = sm
|
||||
sm.add_child(a)
|
||||
sm.on_ground = false
|
||||
sm.current_jump_count = 1
|
||||
_eq(sm.current_jump_count, 1)
|
||||
_expect(
|
||||
sm.current_jump_count < params.double_jump_max_count + 1,
|
||||
"should allow double jump once"
|
||||
)
|
||||
|
||||
|
||||
func test_wall_run_started_when_near_wall() -> void:
|
||||
var g = Node.new()
|
||||
g.name = "state_ground"
|
||||
g.machine = sm
|
||||
sm.add_child(g)
|
||||
var a = Node.new()
|
||||
a.name = "state_air"
|
||||
a.machine = sm
|
||||
sm.add_child(a)
|
||||
sm.wall_normal = Vector3.RIGHT.normalized()
|
||||
sm.switch_to("wall_run")
|
||||
_eq(sm.current_state, "wall_run")
|
||||
|
||||
|
||||
func test_chain_bonus_caps_at_50pct() -> void:
|
||||
params.chain_bonus_per_success = 0.05
|
||||
params.chain_bonus_cap = 0.50
|
||||
sm.register_chain_mechanic("jump")
|
||||
sm.register_chain_mechanic("slide")
|
||||
sm.register_chain_mechanic("wall_run")
|
||||
_expect(sm.chain_count == 3, "chain_count 3 after 3 mechanics")
|
||||
_expect(
|
||||
sm.current_chain_bonus <= params.chain_bonus_cap + 0.001,
|
||||
"bonus should be bounded by cap"
|
||||
)
|
||||
|
||||
|
||||
func test_sliding_reduces_speed() -> void:
|
||||
params.slide_speed = 14.0
|
||||
params.slide_min_speed = 12.0
|
||||
_expect(params.slide_min_speed < params.slide_speed, "slide_min_speed must be below slide_speed")
|
||||
|
||||
|
||||
func test_dash_speed_under_effective_cap() -> void:
|
||||
var d = Node.new()
|
||||
d.name = "state_dash"
|
||||
d.machine = sm
|
||||
sm.add_child(d)
|
||||
sm.on_ground = false
|
||||
var eff := sm.get_effective_speed(params.dash_speed)
|
||||
_expect(
|
||||
eff <= params.dash_speed * (1.0 + params.chain_bonus_cap),
|
||||
"dash effective speed should respect chain cap"
|
||||
)
|
||||
|
||||
|
||||
func test_rocket_jump_impulse_sets_upward_velocity() -> void:
|
||||
params.rocket_jump_up_impulse = 20.0
|
||||
_expect(params.rocket_jump_up_impulse > 0.0, "rocket jump must have positive upward impulse")
|
||||
@@ -0,0 +1 @@
|
||||
uid://c03vjfgs3wvmp
|
||||
@@ -11,9 +11,73 @@ config_version=5
|
||||
[application]
|
||||
|
||||
config/name="Papaya-Shooter"
|
||||
run/main_scene="res://scenes/test_level/test_level.tscn"
|
||||
config/features=PackedStringArray("4.6", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[input]
|
||||
|
||||
move_forward={
|
||||
"deadzone": 0.0,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":87,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
move_back={
|
||||
"deadzone": 0.0,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":83,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
move_left={
|
||||
"deadzone": 0.0,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":65,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
move_right={
|
||||
"deadzone": 0.0,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":68,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
jump={
|
||||
"deadzone": 0.0,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":32,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
sprint={
|
||||
"deadzone": 0.0,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194325,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
crouch={
|
||||
"deadzone": 0.0,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194326,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
dash={
|
||||
"deadzone": 0.0,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194325,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
fire={
|
||||
"deadzone": 0.0,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
fire_alt={
|
||||
"deadzone": 0.0,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":2,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
interact={
|
||||
"deadzone": 0.0,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":69,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
reload={
|
||||
"deadzone": 0.0,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":82,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[physics]
|
||||
|
||||
3d/physics_engine="Jolt Physics"
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
[gd_scene format=3 uid="uid://c5k51gbegvxss"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://c7ltcn37gfd71" path="res://debug/test_level_builder.gd" id="1"]
|
||||
|
||||
[node name="TestLevel" type="Node3D" unique_id=130984349]
|
||||
script = ExtResource("1")
|
||||
Reference in New Issue
Block a user