HeliosApp/scenes/camera_rotation.gd

22 lines
627 B
GDScript

extends Node3D
var last_mouse_pos: Vector2 = Vector2.ZERO
func rotate_camera():
var pos = get_viewport().get_mouse_position()
var change = pos - last_mouse_pos
var rotate_amt = Vector3(-change.y, -change.x, 0) * 0.01
var new_rotation = rotation + rotate_amt
if new_rotation.y > PI*2:
new_rotation.y -= PI*2
elif new_rotation.y < 0:
new_rotation.y += PI*2
rotation = new_rotation.clamp(Vector3(deg_to_rad(-80), -1, 0), Vector3(deg_to_rad(1), PI*2+1, 0))
func _process(delta: float) -> void:
if Input.is_action_pressed("move_camera"):
rotate_camera()
last_mouse_pos = get_viewport().get_mouse_position()