From 914512435d37d9f1e1ea4c045afd4ec5612b7534 Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Sun, 30 Jul 2023 02:45:36 +0100 Subject: Replace movement controllers --- .../component/camera/SpectatorCameraComponent.cs | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 code/pawn/component/camera/SpectatorCameraComponent.cs (limited to 'code/pawn/component/camera/SpectatorCameraComponent.cs') diff --git a/code/pawn/component/camera/SpectatorCameraComponent.cs b/code/pawn/component/camera/SpectatorCameraComponent.cs new file mode 100644 index 0000000..f81e186 --- /dev/null +++ b/code/pawn/component/camera/SpectatorCameraComponent.cs @@ -0,0 +1,41 @@ +using Sandbox; +using System.Collections.Generic; +using System.Linq; + +namespace MurderGame; + +public class SpectatorCameraComponent : BaseCameraComponent +{ + public Player Target { get; set; } + + public override void Simulate( IClient cl ) + { + if (Target == null || !Target.IsValid() || Target.LifeState == LifeState.Dead) + { + var targets = GetTargets(); + if ( targets.Count == 0 ) + { + Target = null; + return; + } + var nextTarget = targets.First(); + Target = (Player)nextTarget.Pawn; + } + } + + public override void FrameSimulate( IClient cl ) + { + if ( Target == null || !Target.IsValid() || Target.LifeState == LifeState.Dead ) return; + + Camera.Rotation = Target.EyeRotation; + Camera.FieldOfView = Screen.CreateVerticalFieldOfView( Game.Preferences.FieldOfView ); + + Camera.FirstPersonViewer = Target; + Camera.Position = Target.EyePosition; + } + + private List GetTargets() + { + return Game.Clients.Where(c => c.Pawn is Player player && player.CurrentTeam != Team.Spectator && player.LifeState == LifeState.Alive).ToList(); + } +} -- cgit v1.2.3-70-g09d2