mirror of
https://github.com/tonytins/citylimits
synced 2025-05-05 14:14:49 -04:00
49 lines
1,021 B
GDScript
49 lines
1,021 B
GDScript
extends Node3D
|
|
|
|
var camera_position:Vector3
|
|
var camera_rotation:Vector3
|
|
|
|
@onready var camera = $Camera
|
|
|
|
func _ready():
|
|
|
|
camera_rotation = rotation_degrees # Initial rotation
|
|
|
|
pass
|
|
|
|
func _process(delta):
|
|
|
|
# Set position and rotation to targets
|
|
|
|
position = position.lerp(camera_position, delta * 8)
|
|
rotation_degrees = rotation_degrees.lerp(camera_rotation, delta * 6)
|
|
|
|
handle_input(delta)
|
|
|
|
# Handle input
|
|
|
|
func handle_input(_delta):
|
|
|
|
# Rotation
|
|
|
|
var input := Vector3.ZERO
|
|
|
|
input.x = Input.get_axis("camera_left", "camera_right")
|
|
input.z = Input.get_axis("camera_forward", "camera_back")
|
|
|
|
input = input.rotated(Vector3.UP, rotation.y).normalized()
|
|
|
|
camera_position += input / 4
|
|
|
|
# Back to center
|
|
|
|
if Input.is_action_pressed("camera_center"):
|
|
camera_position = Vector3()
|
|
|
|
func _input(event):
|
|
|
|
# Rotate camera using mouse (hold 'middle' mouse button)
|
|
|
|
if event is InputEventMouseMotion:
|
|
if Input.is_action_pressed("camera_rotate"):
|
|
camera_rotation += Vector3(0, -event.relative.x / 10, 0)
|