hurrmmm/godot/control_scheme/controller.gd

34 lines
867 B
GDScript

extends Node3D
@export var camera: Camera3D
@export var initial_target: Node3D
var target: Targetable = null
@export var sensitivity := 0.01
func _ready():
set_target(initial_target)
func _input(event):
if event is InputEventMouseMotion:
rotate_view(event.relative*sensitivity)
func _process(_delta):
transform.origin = target.global_position
camera.global_position = %camera_spot.global_position
camera.look_at(target.global_position)
func rotate_view(amount: Vector2):
rotate_y(-amount.x)
%rotate_helper.rotate_z(amount.y)
%rotate_helper.rotation_degrees.z = clampf(%rotate_helper.rotation_degrees.z, -77, 77)
func set_target(node: Node3D):
var ntarget = Targetable.is_targetable(node)
if ntarget == null:
push_error("Node is node targetable", node)
return
if target != null:
target.unmake_target()
ntarget.make_target()
target = ntarget