From dbf0218371ce006b674b0ede8e6a4d97932ff2c6 Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Tue, 1 Aug 2023 01:31:25 +0100 Subject: Add footprints --- code/pawn/component/FootprintTrackerComponent.cs | 51 ++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 code/pawn/component/FootprintTrackerComponent.cs (limited to 'code/pawn/component') diff --git a/code/pawn/component/FootprintTrackerComponent.cs b/code/pawn/component/FootprintTrackerComponent.cs new file mode 100644 index 0000000..7a396d1 --- /dev/null +++ b/code/pawn/component/FootprintTrackerComponent.cs @@ -0,0 +1,51 @@ +using System.Linq; +using Sandbox; + +namespace MurderGame; + +public class FootprintTrackerComponent : EntityComponent, ISingletonComponent +{ + private TimeSince TimeSinceFootstep = 0; + private bool FootstepLeft = true; + + public void Simulate( IClient cl ) + { + if (!Game.IsClient || TimeSinceFootstep < 0.25) return; + TimeSinceFootstep = 0; + FootstepLeft = !FootstepLeft; + + var bystanders = Game.Clients.Where(c => (c.Pawn as Player)?.Team is Team.Bystander or Team.Detective); + + foreach (var bystander in bystanders) + { + if (bystander.Pawn is not Player player) continue; + if (player.Velocity.Length < 1) continue; + var start = player.Position + Vector3.Up; + var end = start + Vector3.Down * 20; + + var tr = Trace.Ray( start, end ) + .Size( 2) + .WithAnyTags( "solid" ) + .Ignore( Entity ) + .Run(); + + if ( !tr.Hit ) + { + continue; + } + + var material = FootstepLeft + ? "materials/left_shoe_footprint.vmat" + : "materials/right_shoe_footprint.vmat"; + var _ = new Footprint + { + SpriteMaterial = Material.Load(material), + SpriteScale = 24f, + Position = player.Position + (Vector3.Up * 1f), + Rotation = Rotation.LookAt(player.Velocity, tr.Normal).RotateAroundAxis( tr.Normal, 270 ), + Color = player.Color + }; + } + } + +} -- cgit v1.2.3-70-g09d2