diff --git a/EXILED/Exiled.API/Features/Player.cs b/EXILED/Exiled.API/Features/Player.cs index d91e703c0..2c005a3d2 100644 --- a/EXILED/Exiled.API/Features/Player.cs +++ b/EXILED/Exiled.API/Features/Player.cs @@ -3973,6 +3973,50 @@ public bool TryGetComponent(Type type, out T component) return component is not null; } + /// + /// Gets the raycast hit information from player. + /// + /// The max distance the raycast can reach. + /// Layers that are included in the raycast. + /// if any. + public RaycastHit? GetRaycast(float maxDistance, LayerMasks layerMask) + => GetRaycast(maxDistance, (int)layerMask); + + /// + /// Gets the raycast hit information from player. + /// + /// The max distance the raycast can reach. + /// Layers that are included in the raycast. + /// if any. + public RaycastHit? GetRaycast(float maxDistance, int layerMask) + { + if (!Physics.Raycast(CameraTransform.position, CameraTransform.forward, out RaycastHit raycastHit, maxDistance, layerMask)) + { + // The raycast was out of bounds. + return null; + } + + return raycastHit; + } + + /// + /// Gets the player hitbox currently looking at if any. + /// + /// The max distance the raycast can reach. + /// if any. + public HitboxIdentity GetRaycastedHitbox(float maxDistance) + { + return GetRaycast(maxDistance, LayerMasks.Hitbox)?.collider.gameObject.GetComponent(); + } + + /// + /// Gets the player currently looking at if any. + /// + /// The max distance the raycast can reach. + /// if any. + public Player GetRaycastedPlayer(float maxDistance) => + Get(GetRaycast(maxDistance, LayerMasks.Hitbox)?.collider); + /// public bool HasComponent(bool depthInheritance = false) => depthInheritance ? componentsInChildren.Any(comp => typeof(T).IsSubclassOf(comp.GetType()))