Initial commit
This commit is contained in:
29
actors/Player/spectator.gd
Normal file
29
actors/Player/spectator.gd
Normal file
@@ -0,0 +1,29 @@
|
||||
extends Node3D
|
||||
|
||||
var followTarget: Node3D
|
||||
var followedPlayerIndex: int = 0
|
||||
var mouseSensetivity: float = 0.1
|
||||
|
||||
func _ready() -> void:
|
||||
activateCamera()
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
updateFollowTarget()
|
||||
if followTarget:
|
||||
global_position = followTarget.global_position
|
||||
|
||||
func _input(event: InputEvent) -> void: #Camera movement with mouse
|
||||
if event is InputEventMouseMotion && Input.mouse_mode == 2:
|
||||
rotation.x = clampf(rotation.x - deg_to_rad(event.relative.y * mouseSensetivity),-PI/8,PI/4)
|
||||
rotation.y -= deg_to_rad(event.relative.x * mouseSensetivity)
|
||||
|
||||
func updateFollowTarget() -> void:
|
||||
if Input.is_action_just_pressed("throw"):
|
||||
followedPlayerIndex += 1
|
||||
if followedPlayerIndex >= Multiplayer.playerDict.size():
|
||||
followedPlayerIndex = 0
|
||||
|
||||
followTarget = Multiplayer.playerDict.values()[followedPlayerIndex]
|
||||
|
||||
func activateCamera() -> void:
|
||||
$SpringArm3D/Camera3D.current = true
|
||||
Reference in New Issue
Block a user