grounders-slowjam-2024/camera/camera.gd

30 lines
749 B
GDScript

extends Node3D
const MOUSE_SENSITIVITY := .001
func get_input_direction() -> Vector2:
var input := Input.get_vector("move_left", "move_right", "move_up", "move_down")
if input == Vector2.ZERO:
return Vector2.ZERO
var dir := input.normalized()
input = input * dir.abs()
return -1.0 * dir.rotated(-rotation.y + PI)
func _process(_delta):
get_parent().movement_dir = get_input_direction()
%SpringArm3D.look_at(global_position)
func _ready():
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
func handle_camera_movement(move: Vector2):
if Input.mouse_mode != Input.MOUSE_MODE_CAPTURED:
return
move *= MOUSE_SENSITIVITY
rotate_y(-move.x)
func _input(event):
if event is InputEventMouseMotion:
handle_camera_movement(event.relative)