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,6 @@
|
||||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://test/capture/camera_scene.gd" id="1"]
|
||||
|
||||
[node name="CaptureCamera" type="Node3D"]
|
||||
script = ExtResource("1")
|
||||
@@ -0,0 +1,8 @@
|
||||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://test/capture/camera_scene.gd" id="1"]
|
||||
|
||||
[node name="CaptureCameraAim" type="Node3D"]
|
||||
script = ExtResource("1")
|
||||
yaw_degrees = 20.0
|
||||
aiming = true
|
||||
@@ -0,0 +1,26 @@
|
||||
## Capture scenario for the third-person camera: the shore scene with a stand-in player,
|
||||
## viewed through PlayerCamera and CameraRig as in the game.
|
||||
extends "res://test/capture/smoke_scene.gd"
|
||||
|
||||
@export var feet: Vector3 = Vector3(1.0, 0.0, 0.5)
|
||||
@export var yaw_degrees: float = 0.0
|
||||
@export var pitch_degrees: float = -8.0
|
||||
@export var aiming: bool = false
|
||||
|
||||
|
||||
func _add_camera() -> void:
|
||||
var body: CapsuleMesh = CapsuleMesh.new()
|
||||
body.radius = Tuning.PLAYER_RADIUS
|
||||
body.height = Tuning.PLAYER_HEIGHT
|
||||
_place(body, feet + Vector3.UP * Tuning.PLAYER_HEIGHT * 0.5, Color(0.2, 0.42, 0.36))
|
||||
var camera: PlayerCamera = PlayerCamera.new()
|
||||
camera.ground = ground
|
||||
camera.target_feet = feet
|
||||
camera.yaw = deg_to_rad(yaw_degrees)
|
||||
camera.pitch = deg_to_rad(pitch_degrees)
|
||||
camera.aiming = aiming
|
||||
if aiming:
|
||||
camera.rig.aim_blend = 1.0
|
||||
add_child(camera)
|
||||
camera.make_current()
|
||||
camera.snap()
|
||||
@@ -0,0 +1 @@
|
||||
uid://cxokowai701cm
|
||||
@@ -0,0 +1,9 @@
|
||||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://test/capture/camera_scene.gd" id="1"]
|
||||
|
||||
[node name="CaptureCameraWall" type="Node3D"]
|
||||
script = ExtResource("1")
|
||||
feet = Vector3(-1.5, 0, 2.4)
|
||||
yaw_degrees = 180.0
|
||||
pitch_degrees = -5.0
|
||||
@@ -2,6 +2,9 @@
|
||||
## post, under a procedural sky. Everything is built in code, so there are no assets.
|
||||
extends Node3D
|
||||
|
||||
## The solid shape of the scene, for scenarios that need collision (the camera rig).
|
||||
var ground: SimGround = SimGround.flat(0.0)
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var environment: Environment = Environment.new()
|
||||
@@ -35,6 +38,11 @@ func _ready() -> void:
|
||||
_cylinder(0.35, 5.0, Vector3(5.0, 2.5, -2.0), Color(0.55, 0.36, 0.22))
|
||||
_cylinder(0.6, 0.8, Vector3(5.0, 5.4, -2.0), Color(0.72, 0.22, 0.18))
|
||||
|
||||
_add_camera()
|
||||
|
||||
|
||||
## Override to view the scene differently.
|
||||
func _add_camera() -> void:
|
||||
var camera: Camera3D = Camera3D.new()
|
||||
camera.position = Vector3(-6.0, 6.0, -16.0)
|
||||
add_child(camera)
|
||||
@@ -46,9 +54,12 @@ func _box(size: Vector3, at: Vector3, colour: Color) -> void:
|
||||
var mesh: BoxMesh = BoxMesh.new()
|
||||
mesh.size = size
|
||||
_place(mesh, at, colour)
|
||||
if at.y + size.y * 0.5 > 0.0:
|
||||
ground.add_solid(AABB(at - size * 0.5, size))
|
||||
|
||||
|
||||
func _cylinder(radius: float, height: float, at: Vector3, colour: Color) -> void:
|
||||
ground.add_solid(AABB(at - Vector3(radius, height * 0.5, radius), Vector3(radius * 2.0, height, radius * 2.0)))
|
||||
var mesh: CylinderMesh = CylinderMesh.new()
|
||||
mesh.top_radius = radius
|
||||
mesh.bottom_radius = radius
|
||||
|
||||
Reference in New Issue
Block a user