Files
CharacterContoller/characters/samus/samus.gd
2025-07-20 10:34:21 +02:00

50 lines
1.6 KiB
GDScript

extends CharacterBody3D
@export var state_machine: LimboHSM
@onready var idle_state: LimboState = $LimboHSM/Idle
@export var move_pcam : PhantomCamera3D
@export var mouse_sensitivity: float = 0.05
@export var min_pitch: float = -89.9
@export var max_pitch: float = 50
@export var min_yaw: float = 0
@export var max_yaw: float = 360
func _ready() -> void:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
_initialize_state_machine()
func _initialize_state_machine() -> void:
state_machine.initial_state = idle_state
state_machine.initialize(self)
state_machine.set_active(true)
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventMouseMotion:
var pcam_rotation_degrees: Vector3
# Assigns the current 3D rotation of the SpringArm3D node - so it starts off where it is in the editor
pcam_rotation_degrees = move_pcam.get_third_person_rotation_degrees()
# Change the X rotation
pcam_rotation_degrees.x -= event.relative.y * mouse_sensitivity
# Clamp the rotation in the X axis so it go over or under the target
pcam_rotation_degrees.x = clampf(pcam_rotation_degrees.x, min_pitch, max_pitch)
# Change the Y rotation value
pcam_rotation_degrees.y -= event.relative.x * mouse_sensitivity
# Sets the rotation to fully loop around its target, but witout going below or exceeding 0 and 360 degrees respectively
pcam_rotation_degrees.y = wrapf(pcam_rotation_degrees.y, min_yaw, max_yaw)
# Change the SpringArm3D node's rotation and rotate around its target
move_pcam.set_third_person_rotation_degrees(pcam_rotation_degrees)