W1: Third-person character controller and camera
Simulation (src/sim/): - SimGround holds the terrain heightfield (bilinear heights, normals) and axis-aligned box solids, with support, body-overlap, point and ray queries. The island generator and building will fill it. - Movement steps a player per tick: walk, sprint (forward only), crouch (lower body, slower, no jump), jump with exact constant-gravity integration, air control, step-up onto ledges up to STEP_HEIGHT, ground snapping on downhill walks, slopes over MAX_SLOPE_DEGREES that block walking and jumping uphill and make players slide (speed capped), ceiling bumps, sliding along walls, and fall damage from impact speed. - Gravity now applies on ticks with no command. on_ground and crouching are part of the state hash. New movement numbers are in Tuning. - Fixed the strafe direction: right is forward x up in Godot's frame, (-cos yaw, 0, sin yaw). Documented the look convention. Client (src/client/): - CameraRig places an over-the-shoulder camera with an eased aim-down-sights blend (closer, narrower FOV), casting against the same SimGround: pivot to shoulder, shoulder back, then a straight line from the pivot, with a final clearance pull-in so the near plane never enters geometry. - InputSettings: mouse sensitivity, aim sensitivity scale and invert-Y, clamped and saved to user://settings.cfg. PlayerCamera applies both. Tests: 46 new across movement, ground queries, camera and settings, including a 24,480-view scripted camera sweep through five arenas (wall, corridor, low roof, corner, steep bank) that checks the eye and every near-plane corner stay out of geometry with a clear line to the pivot. The hash test now flips a high stick bit, because a 1/127 nudge to an airborne player moves them less than the hash's millimetre. Capture scenarios camera, camera_wall and camera_aim. Closes #8 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
extends TestCase
|
||||
|
||||
const PATH: String = "user://test_input_settings.cfg"
|
||||
|
||||
|
||||
func after_each() -> void:
|
||||
if FileAccess.file_exists(PATH):
|
||||
DirAccess.remove_absolute(ProjectSettings.globalize_path(PATH))
|
||||
|
||||
|
||||
func test_sensitivity_scales_turning() -> void:
|
||||
var settings: InputSettings = InputSettings.new()
|
||||
var slow: Vector2 = settings.apply_mouse(Vector2(100.0, 0.0), 1.0, 0.0, false)
|
||||
settings.mouse_sensitivity = 2.0
|
||||
var fast: Vector2 = settings.apply_mouse(Vector2(100.0, 0.0), 1.0, 0.0, false)
|
||||
assert_near(1.0 - slow.x, 100.0 * InputSettings.RADIANS_PER_PIXEL, 0.00001)
|
||||
assert_near(1.0 - fast.x, 2.0 * (1.0 - slow.x), 0.00001)
|
||||
|
||||
|
||||
func test_mouse_right_turns_right_and_up_looks_up() -> void:
|
||||
var settings: InputSettings = InputSettings.new()
|
||||
var look: Vector2 = settings.apply_mouse(Vector2(10.0, -10.0), 1.0, 0.0, false)
|
||||
assert_true(look.x < 1.0, "turning right decreases yaw")
|
||||
assert_true(look.y > 0.0, "mouse up looks up")
|
||||
settings.invert_y = true
|
||||
assert_true(settings.apply_mouse(Vector2(0.0, -10.0), 1.0, 0.0, false).y < 0.0)
|
||||
|
||||
|
||||
func test_aiming_slows_the_mouse() -> void:
|
||||
var settings: InputSettings = InputSettings.new()
|
||||
var hip: Vector2 = settings.apply_mouse(Vector2(50.0, 0.0), 1.0, 0.0, false)
|
||||
var aimed: Vector2 = settings.apply_mouse(Vector2(50.0, 0.0), 1.0, 0.0, true)
|
||||
assert_near(1.0 - aimed.x, (1.0 - hip.x) * settings.aim_sensitivity_scale, 0.00001)
|
||||
|
||||
|
||||
func test_pitch_is_clamped_and_yaw_wraps() -> void:
|
||||
var settings: InputSettings = InputSettings.new()
|
||||
var look: Vector2 = settings.apply_mouse(Vector2(-10.0, -100000.0), TAU - 0.001, 0.0, false)
|
||||
assert_near(look.y, InputSettings.PITCH_LIMIT, 0.00001)
|
||||
assert_true(look.x >= 0.0 and look.x < TAU)
|
||||
|
||||
|
||||
func test_sensitivity_is_clamped() -> void:
|
||||
var settings: InputSettings = InputSettings.new()
|
||||
settings.mouse_sensitivity = 0.0
|
||||
assert_eq(settings.mouse_sensitivity, InputSettings.MIN_SENSITIVITY)
|
||||
settings.mouse_sensitivity = 1000.0
|
||||
assert_eq(settings.mouse_sensitivity, InputSettings.MAX_SENSITIVITY)
|
||||
|
||||
|
||||
func test_settings_round_trip_through_the_config_file() -> void:
|
||||
var settings: InputSettings = InputSettings.new()
|
||||
settings.mouse_sensitivity = 2.75
|
||||
settings.aim_sensitivity_scale = 0.4
|
||||
settings.invert_y = true
|
||||
assert_eq(settings.save(PATH), OK)
|
||||
var loaded: InputSettings = InputSettings.load_from(PATH)
|
||||
assert_near(loaded.mouse_sensitivity, 2.75, 0.0001)
|
||||
assert_near(loaded.aim_sensitivity_scale, 0.4, 0.0001)
|
||||
assert_true(loaded.invert_y)
|
||||
|
||||
|
||||
func test_missing_or_bad_file_gives_defaults() -> void:
|
||||
assert_eq(InputSettings.load_from("user://does_not_exist.cfg").mouse_sensitivity, 1.0)
|
||||
var config: ConfigFile = ConfigFile.new()
|
||||
config.set_value(InputSettings.SECTION, "mouse_sensitivity", "fast")
|
||||
config.save(PATH)
|
||||
assert_eq(InputSettings.load_from(PATH).mouse_sensitivity, 1.0)
|
||||
Reference in New Issue
Block a user