From 7cc6031dc112f72698d60e4e42453cb9bef09351 Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Mon, 31 Jul 2023 02:59:08 +0100 Subject: Add looking at info --- code/pawn/Player.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'code/pawn') diff --git a/code/pawn/Player.cs b/code/pawn/Player.cs index 1d87d94..7073bb1 100644 --- a/code/pawn/Player.cs +++ b/code/pawn/Player.cs @@ -60,6 +60,8 @@ public partial class Player : AnimatedEntity [Net, Predicted] public TimeSince TimeSinceDeath { get; set; } = 0; + public Player LookingAt { get; set; } + public override void Spawn() { SetModel( "models/citizen/citizen.vmdl" ); @@ -189,6 +191,29 @@ public partial class Player : AnimatedEntity Components.Create(); } + if ( Game.IsClient ) + { + var start = AimRay.Position; + var end = AimRay.Position + AimRay.Forward * 5000; + + var trace = Trace.Ray( start, end ) + .UseHitboxes() + .WithAnyTags( "solid", "livingplayer" ) + .Ignore( this ) + .Size( 1f ); + + var tr = trace.Run(); + if ( tr.Hit && tr.Entity.IsValid() && tr.Entity is Player player ) + { + LookingAt = player; + } + else + { + LookingAt = null; + } + } + + } public override void BuildInput() -- cgit v1.2.3-70-g09d2