diff options
Diffstat (limited to 'code/pawn/component/camera/SpectatorCameraComponent.cs')
| -rw-r--r-- | code/pawn/component/camera/SpectatorCameraComponent.cs | 41 |
1 files changed, 41 insertions, 0 deletions
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<IClient> GetTargets()
+ {
+ return Game.Clients.Where(c => c.Pawn is Player player && player.CurrentTeam != Team.Spectator && player.LifeState == LifeState.Alive).ToList();
+ }
+}
|
