Godot 4.6 exploration game with player movement, step-rotation camera rig, and POI interaction system (explore/rest/close menu). main.tscn is a test scene with placeholder props; debug/ holds unwired terrain prototypes (voxel river, procedural island mesh, cross-shaped hub
35 lines
1.3 KiB
GDScript
35 lines
1.3 KiB
GDScript
extends Node3D
|
|
|
|
@export var fly_speed : float = 20.0
|
|
@export var fast_speed : float = 60.0
|
|
@export var sensitivity: float = 0.003
|
|
|
|
var yaw : float = PI
|
|
var pitch : float = -0.38
|
|
var captured: bool = false
|
|
|
|
func _unhandled_input(e: InputEvent) -> void:
|
|
if e is InputEventMouseButton and e.button_index == MOUSE_BUTTON_RIGHT:
|
|
captured = e.pressed
|
|
Input.set_mouse_mode(
|
|
Input.MOUSE_MODE_CAPTURED if captured else Input.MOUSE_MODE_VISIBLE)
|
|
if e is InputEventMouseMotion and captured:
|
|
yaw -= e.relative.x * sensitivity
|
|
pitch = clamp(pitch - e.relative.y * sensitivity, -1.4, 0.2)
|
|
rotation = Vector3(pitch, yaw, 0)
|
|
if e is InputEventKey and e.pressed and e.keycode == KEY_ESCAPE:
|
|
captured = false
|
|
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
|
|
|
func _process(delta: float) -> void:
|
|
var spd := fast_speed if Input.is_key_pressed(KEY_SHIFT) else fly_speed
|
|
var move := Vector3.ZERO
|
|
if Input.is_key_pressed(KEY_W): move -= global_transform.basis.z
|
|
if Input.is_key_pressed(KEY_S): move += global_transform.basis.z
|
|
if Input.is_key_pressed(KEY_A): move -= global_transform.basis.x
|
|
if Input.is_key_pressed(KEY_D): move += global_transform.basis.x
|
|
if Input.is_key_pressed(KEY_E): move += Vector3.UP
|
|
if Input.is_key_pressed(KEY_Q): move -= Vector3.UP
|
|
if move.length_squared() > 0:
|
|
position += move.normalized() * spd * delta
|