Phase 0: Greybox-Fundament
- Input-Map: alle Actions aus SPEC 9 (Tastatur + Xbox/PS5, physische Keycodes, Deadzone 0.2) - 11 Autoload-Skelette (SPEC 8) mit Doku-Bloecken, ohne Logik - Greybox-Testszene test_ground.tscn: Boden, Hindernisse, Spieler-Kapsel, Third-Person-Kamera (WoW-Zoom via SpringArm3D), WorldEnvironment - Debug-Overlay: FPS, aktives Eingabegeraet, Position, Kamera-Zoom - test_ground.tscn als Main Scene gesetzt Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
commit
f4c67ceead
40 changed files with 1064 additions and 0 deletions
0
scripts/gameplay/.gitkeep
Normal file
0
scripts/gameplay/.gitkeep
Normal file
130
scripts/gameplay/player.gd
Normal file
130
scripts/gameplay/player.gd
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
extends CharacterBody3D
|
||||
## Greybox-Spielersteuerung für Phase 0.
|
||||
##
|
||||
## Bewegt die Spieler-Kapsel relativ zur Kamera (WASD + linker Stick),
|
||||
## unterstützt Sprint und steuert die weit rausgezoomte Third-Person-Kamera
|
||||
## im WoW-Stil: Orbit über Maus und rechten Stick, Zoom über Mausrad und
|
||||
## Schultertasten, Kollision über SpringArm3D. Die Actions look_x/look_y
|
||||
## sind in der Input-Map registriert; Mausbewegung ist in Godot nicht auf
|
||||
## Actions mappbar und wird deshalb direkt als InputEventMouseMotion
|
||||
## gelesen, der rechte Stick direkt über die Joypad-Achsen (Deadzone 0.2).
|
||||
|
||||
const WALK_SPEED := 4.0
|
||||
const SPRINT_SPEED := 7.5
|
||||
const STOP_SPEED := 16.0
|
||||
const MESH_TURN_SPEED := 10.0
|
||||
const MOUSE_SENSITIVITY := 0.003
|
||||
const STICK_LOOK_SPEED := 2.5
|
||||
const STICK_DEADZONE := 0.2
|
||||
const PITCH_MIN := -1.2
|
||||
const PITCH_MAX := 0.5
|
||||
const ZOOM_MIN := 2.0
|
||||
const ZOOM_MAX := 14.0
|
||||
const ZOOM_STEP := 0.8
|
||||
const ZOOM_BUTTON_SPEED := 8.0
|
||||
const ZOOM_SMOOTHING := 10.0
|
||||
|
||||
var _target_zoom := 9.0
|
||||
var _gravity: float = ProjectSettings.get_setting("physics/3d/default_gravity")
|
||||
|
||||
@onready var _camera_pivot: Node3D = $CameraPivot
|
||||
@onready var _spring_arm: SpringArm3D = $CameraPivot/SpringArm3D
|
||||
@onready var _mesh: MeshInstance3D = $MeshInstance3D
|
||||
|
||||
|
||||
## Fängt den Mauszeiger ein und übernimmt die im Editor gesetzte
|
||||
## SpringArm-Länge als Zoom-Ziel.
|
||||
func _ready() -> void:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
_target_zoom = _spring_arm.spring_length
|
||||
|
||||
|
||||
## Verarbeitet Maus-Look, Mausrad-Zoom sowie das Freigeben des Cursors über
|
||||
## cancel und das Wieder-Einfangen per Mausklick.
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
|
||||
_rotate_camera(-event.relative.x * MOUSE_SENSITIVITY, -event.relative.y * MOUSE_SENSITIVITY)
|
||||
elif event is InputEventMouseButton and event.pressed:
|
||||
if event.is_action("camera_zoom_in"):
|
||||
_target_zoom = clampf(_target_zoom - ZOOM_STEP, ZOOM_MIN, ZOOM_MAX)
|
||||
elif event.is_action("camera_zoom_out"):
|
||||
_target_zoom = clampf(_target_zoom + ZOOM_STEP, ZOOM_MIN, ZOOM_MAX)
|
||||
elif Input.get_mouse_mode() != Input.MOUSE_MODE_CAPTURED:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
elif event.is_action_pressed("cancel"):
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
|
||||
|
||||
## Treibt pro Physik-Tick Stick-Look, Schultertasten-Zoom, Zoom-Glättung und
|
||||
## Bewegung an.
|
||||
func _physics_process(delta: float) -> void:
|
||||
_apply_stick_look(delta)
|
||||
_apply_button_zoom(delta)
|
||||
_apply_zoom_smoothing(delta)
|
||||
_apply_movement(delta)
|
||||
|
||||
|
||||
## Liefert die aktuelle Kamera-Distanz in Metern für das Debug-Overlay.
|
||||
func get_camera_zoom() -> float:
|
||||
return _spring_arm.spring_length
|
||||
|
||||
|
||||
## Dreht die Kamera um yaw_delta (horizontal, am Pivot) und pitch_delta
|
||||
## (vertikal, am SpringArm, begrenzt auf PITCH_MIN..PITCH_MAX). Beide Werte
|
||||
## in Radiant.
|
||||
func _rotate_camera(yaw_delta: float, pitch_delta: float) -> void:
|
||||
_camera_pivot.rotation.y = wrapf(_camera_pivot.rotation.y + yaw_delta, -PI, PI)
|
||||
_spring_arm.rotation.x = clampf(_spring_arm.rotation.x + pitch_delta, PITCH_MIN, PITCH_MAX)
|
||||
|
||||
|
||||
## Liest den rechten Stick des ersten aktiven Controllers und dreht die
|
||||
## Kamera zeitbasiert.
|
||||
func _apply_stick_look(delta: float) -> void:
|
||||
var stick := Vector2(
|
||||
_read_joy_axis(JOY_AXIS_RIGHT_X),
|
||||
_read_joy_axis(JOY_AXIS_RIGHT_Y)
|
||||
)
|
||||
if stick != Vector2.ZERO:
|
||||
_rotate_camera(-stick.x * STICK_LOOK_SPEED * delta, -stick.y * STICK_LOOK_SPEED * delta)
|
||||
|
||||
|
||||
## Zoomt kontinuierlich, solange eine Schultertaste gehalten wird.
|
||||
func _apply_button_zoom(delta: float) -> void:
|
||||
var zoom_input := Input.get_action_strength("camera_zoom_out") - Input.get_action_strength("camera_zoom_in")
|
||||
if zoom_input != 0.0:
|
||||
_target_zoom = clampf(_target_zoom + zoom_input * ZOOM_BUTTON_SPEED * delta, ZOOM_MIN, ZOOM_MAX)
|
||||
|
||||
|
||||
## Führt die SpringArm-Länge weich an das Zoom-Ziel heran.
|
||||
func _apply_zoom_smoothing(delta: float) -> void:
|
||||
_spring_arm.spring_length = lerpf(_spring_arm.spring_length, _target_zoom, minf(ZOOM_SMOOTHING * delta, 1.0))
|
||||
|
||||
|
||||
## Wendet Schwerkraft an, bewegt den Spieler kamerarelativ mit Geh- oder
|
||||
## Sprint-Tempo und dreht das Kapsel-Mesh weich in Laufrichtung.
|
||||
func _apply_movement(delta: float) -> void:
|
||||
if not is_on_floor():
|
||||
velocity.y -= _gravity * delta
|
||||
var input_dir := Input.get_vector("move_left", "move_right", "move_forward", "move_back")
|
||||
var direction := _camera_pivot.global_transform.basis * Vector3(input_dir.x, 0.0, input_dir.y)
|
||||
direction.y = 0.0
|
||||
var speed := SPRINT_SPEED if Input.is_action_pressed("sprint") else WALK_SPEED
|
||||
if direction.length_squared() > 0.0:
|
||||
velocity.x = direction.x * speed
|
||||
velocity.z = direction.z * speed
|
||||
var target_yaw := atan2(-direction.x, -direction.z)
|
||||
_mesh.rotation.y = lerp_angle(_mesh.rotation.y, target_yaw, minf(MESH_TURN_SPEED * delta, 1.0))
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0.0, STOP_SPEED * delta)
|
||||
velocity.z = move_toward(velocity.z, 0.0, STOP_SPEED * delta)
|
||||
move_and_slide()
|
||||
|
||||
|
||||
## Liest eine Joypad-Achse über alle verbundenen Controller und liefert den
|
||||
## ersten Wert außerhalb der Deadzone, sonst 0.
|
||||
func _read_joy_axis(axis: JoyAxis) -> float:
|
||||
for device in Input.get_connected_joypads():
|
||||
var value := Input.get_joy_axis(device, axis)
|
||||
if absf(value) > STICK_DEADZONE:
|
||||
return value
|
||||
return 0.0
|
||||
Loading…
Add table
Add a link
Reference in a new issue