Move the pilot's point of view with keyboard

This commit is contained in:
Marek S. Łukasiewicz 2025-12-05 18:09:54 +01:00
parent fcea9ab6ed
commit 1f3c747c72
2 changed files with 49 additions and 0 deletions

View file

@ -9,9 +9,11 @@ const CAMERA_X_ROT_MIN := deg_to_rad(-85)
const CAMERA_X_ROT_MAX := deg_to_rad(70)
@export var use_mouse: bool = true
@export var pov_move_speed = 0.05
var active: bool = false
var initial_rotation: Vector3
var initial_pov_position: Vector3
@onready var camera_base = $"."
@onready var camera = $FallbackCamera
@ -20,6 +22,7 @@ func _ready() -> void:
set_process(false)
set_process_input(false)
initial_rotation = camera.rotation
initial_pov_position = position
func _on_aircraft_use_fallback(active_in: bool) -> void:
if active_in:
@ -51,7 +54,15 @@ func _input(event):
if use_mouse and event is InputEventMouseMotion:
var camera_speed_this_frame = CAMERA_MOUSE_ROTATION_SPEED
rotate_camera(event.relative * camera_speed_this_frame * scale_factor)
if event.is_action_pressed("pov_reset"):
position = initial_pov_position
func _process(delta: float):
var horizontal = Input.get_vector("pov_left", "pov_right", "pov_forward", "pov_back")
var vertical = Input.get_axis("pov_down", "pov_up")
# Currently PilotEyes has Yaw 180, so horizontal axes need to be inverted
position += delta * pov_move_speed * Vector3(-horizontal.x, vertical, -horizontal.y)
func rotate_camera(move):
camera_base.rotate_y(-move.x)