SpaceClient/Scripts/Camera.gd

64 lines
2.1 KiB
GDScript

extends Camera
const TRANSLATION_SPEED : float = 0.1
const ROTATION_SPEED : float = 0.025
var players = []
var index : int = 0
var locked : bool = false
func register_player(player):
players.append(player)
func clear_register():
players.clear()
locked = false
index = 0
func _physics_process(delta : float) -> void:
if Input.is_action_pressed("camera_forward"):
translate(TRANSLATION_SPEED * Vector3(0, 0, -1)); locked = false
if Input.is_action_pressed("camera_backward"):
translate(TRANSLATION_SPEED * Vector3(0, 0, 1)); locked = false
if Input.is_action_pressed("camera_strafe_up"):
translate(TRANSLATION_SPEED * Vector3(0, 1, 0)); locked = false
if Input.is_action_pressed("camera_strafe_down"):
translate(TRANSLATION_SPEED * Vector3(0, -1, 0)); locked = false
if Input.is_action_pressed("camera_strafe_right"):
translate(TRANSLATION_SPEED * Vector3(1, 0, 0)); locked = false
if Input.is_action_pressed("camera_strafe_left"):
translate(TRANSLATION_SPEED * Vector3(-1, 0, 0)); locked = false
if Input.is_action_pressed("camera_pitch_down"):
rotate_object_local(Vector3(1,0,0), -ROTATION_SPEED); locked = false
if Input.is_action_pressed("camera_pitch_up"):
rotate_object_local(Vector3(1,0,0), ROTATION_SPEED); locked = false
if Input.is_action_pressed("camera_roll_left"):
rotate_object_local(Vector3(0,0,1), ROTATION_SPEED); locked = false
if Input.is_action_pressed("camera_roll_right"):
rotate_object_local(Vector3(0,0,1), -ROTATION_SPEED); locked = false
if Input.is_action_pressed("camera_yaw_left"):
rotate_object_local(Vector3(0,1,0), ROTATION_SPEED); locked = false
if Input.is_action_pressed("camera_yaw_right"):
rotate_object_local(Vector3(0,1,0), -ROTATION_SPEED); locked = false
if Input.is_action_just_pressed("camera_switch_player"):
move_to_player(index % len(players))
index += 1
locked = true
if locked:
move_to_player(index % len(players))
func move_to_player(index : int):
translation = players[index].translation
rotation = players[index].rotation
translate(Vector3(0, -0.8, -2))
rotate_object_local(Vector3(1,0,0), PI-0.3)