diff --git a/Entities/EntityList.cs b/Entities/EntityList.cs index 46290e156..5179b463b 100644 --- a/Entities/EntityList.cs +++ b/Entities/EntityList.cs @@ -1,4 +1,5 @@ using System; +using OpenTK; namespace ClassicalSharp { @@ -31,6 +32,24 @@ namespace ClassicalSharp { } } + public byte GetClosetPlayer( Vector3 eyePos, Vector3 dir ) { + float dist = float.PositiveInfinity; + byte targetId = 255; + + for( int i = 0; i < Players.Length - 1; i++ ) { // -1 because we don't want to pick against local player + Player p = Players[i]; + if( p == null ) continue; + BoundingBox bounds = p.Bounds; + + float t0, t1; + if( IntersectionUtils.RayIntersectsBox( eyePos, dir, bounds.Min, bounds.Max, out t0, out t1 ) ) { + dist = t0; + targetId = (byte)i; + } + } + return targetId; + } + public Player this[int id] { get { return Players[id]; } set { Players[id] = value; }