2 Commits

Author SHA1 Message Date
mccarreon
b9dbe07e1f fixed camera with lookat functions 2023-08-04 21:16:49 -07:00
mccarreon
4a338d9502 initial file creation 2023-08-03 19:34:23 -07:00
3 changed files with 96 additions and 3 deletions

View File

@@ -3,7 +3,7 @@ using Sandbox;
namespace LuckerGame.Components.Lucker.Cameras;
public abstract class AbstractCamera : EntityComponent<Entities.Lucker>, ISingletonComponent
public abstract partial class AbstractCamera : EntityComponent<Entities.Lucker>, ISingletonComponent
{
public virtual bool ShouldShowCursor => false;
protected Vector3 CameraPosition { get; set; }
@@ -20,7 +20,7 @@ public abstract class AbstractCamera : EntityComponent<Entities.Lucker>, ISingle
/// <summary>
/// Handles any input dependent camera updates (ie moving around a top down cam)
/// </summary>
public abstract void BuildInput();
public virtual void BuildInput() { }
/// <summary>
/// Applies Camera parameters to the static Camera

View File

@@ -0,0 +1,41 @@
using Sandbox;
namespace LuckerGame.Components.Lucker.Cameras;
public partial class FixedCamera : AbstractCamera, ISingletonComponent
{
[Net] public float FieldOfViewValue { get; set; } = 70f;
public override bool ShouldShowCursor => true;
protected override void UpdateCameraParameters()
{
FieldOfView = FieldOfViewValue;
FirstPersonViewer = null;
SoundSource = new Transform { Position = CameraPosition };
}
/// <summary>
/// ClientRpc doesn't allow for nullable versions of non-nullable types
/// so here we are
/// </summary>
public void UpdateCameraPositionRotation( Vector3? position = null, Rotation? rotation = null )
{
CameraPosition = (Vector3)(position.Equals( null ) ? CameraPosition : position);
CameraRotation = (Rotation)(rotation.Equals( null ) ? CameraRotation : rotation);
}
[ClientRpc]
public void LookAt( Vector3 position )
{
UpdateCameraPositionRotation( position );
}
[ClientRpc]
public void LookAt( Rotation rotation )
{
UpdateCameraPositionRotation( rotation: rotation );
}
[ClientRpc]
public void LookAt( Vector3 position, Rotation rotation )
{
UpdateCameraPositionRotation( position, rotation );
}
}

View File

@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using LuckerGame.Components.Lucker.Cameras;
using LuckerGame.Components.Pawn;
using LuckerGame.Entities;
using Sandbox;
using Sandbox.UI;
namespace LuckerGame.Minigames.TerryRaces;
[Library( "mg_terry_races" )]
public class TerryRaces : Minigame
{
public override string Name => "Terry Races";
private List<Lucker> Players { get; set; }
private FixedCamera camera;
public override void Initialize( List<Lucker> players )
{
Players = players;
// Setup cameras for players
Players.ForEach( player =>
{
camera = player.Components.Create<FixedCamera>();
camera.LookAt( new Vector3( -110f, 4f, 180f ), Rotation.FromPitch( 45 ) );
camera.FieldOfViewValue = 120f;
} );
Players.Select( ( player, i ) => (Player: player, Index: i) ).ToList().ForEach( pair =>
{
var player = pair.Player;
var index = pair.Index;
var pawn = new Pawn();
pawn.Name = player.Name;
pawn.Tags.Add( "victim" );
pawn.Health = 1;
player.Pawn = pawn;
pawn.DressFromClient( player.Client );
} );
}
public override void Tick()
{
}
public override void Cleanup()
{
}
}