From 6d9f352cba7cd9f1aee6810f3970943cfdc7b182 Mon Sep 17 00:00:00 2001 From: Saskyc Date: Thu, 26 Mar 2026 16:03:06 +0100 Subject: [PATCH 1/4] Added 2 methods to raycast from players perspective easier for player or anything in layer mask. --- EXILED/Exiled.API/Features/Player.cs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/EXILED/Exiled.API/Features/Player.cs b/EXILED/Exiled.API/Features/Player.cs index d91e703c0..68f023ea6 100644 --- a/EXILED/Exiled.API/Features/Player.cs +++ b/EXILED/Exiled.API/Features/Player.cs @@ -3973,6 +3973,32 @@ 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, 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 currently looking at if any. + /// + /// The max distance the raycast can reach. + /// if any. + public Player GetRaycastedPlayer(float maxDistance) => + Get(GetRaycast(maxDistance, (int)LayerMasks.Player)?.collider); + /// public bool HasComponent(bool depthInheritance = false) => depthInheritance ? componentsInChildren.Any(comp => typeof(T).IsSubclassOf(comp.GetType())) From 1d15d94ed535172d3ad1f74a1b1fa3cf048a9765 Mon Sep 17 00:00:00 2001 From: Saskyc Date: Thu, 26 Mar 2026 16:16:32 +0100 Subject: [PATCH 2/4] Raycast for hitbox and also raycast using the layer masks --- EXILED/Exiled.API/Features/Player.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/EXILED/Exiled.API/Features/Player.cs b/EXILED/Exiled.API/Features/Player.cs index 68f023ea6..71bb4870b 100644 --- a/EXILED/Exiled.API/Features/Player.cs +++ b/EXILED/Exiled.API/Features/Player.cs @@ -3973,6 +3973,15 @@ 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. /// @@ -3991,13 +4000,23 @@ public bool TryGetComponent(Type type, out T component) 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, (int)LayerMasks.Player)?.collider); + Get(GetRaycast(maxDistance, LayerMasks.Player)?.collider); /// public bool HasComponent(bool depthInheritance = false) => depthInheritance From 71b953408669bb07eb9d4a23a56a8cda8b39dd5c Mon Sep 17 00:00:00 2001 From: Saskyc Date: Thu, 26 Mar 2026 16:20:40 +0100 Subject: [PATCH 3/4] Stylescope is killing me --- EXILED/Exiled.API/Features/Player.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/EXILED/Exiled.API/Features/Player.cs b/EXILED/Exiled.API/Features/Player.cs index 71bb4870b..a2cb7de65 100644 --- a/EXILED/Exiled.API/Features/Player.cs +++ b/EXILED/Exiled.API/Features/Player.cs @@ -3990,8 +3990,7 @@ public bool TryGetComponent(Type type, out T component) /// if any. public RaycastHit? GetRaycast(float maxDistance, int layerMask) { - if (!Physics.Raycast(CameraTransform.position, CameraTransform.forward, out RaycastHit raycastHit, - maxDistance, layerMask)) + if (!Physics.Raycast(CameraTransform.position, CameraTransform.forward, out RaycastHit raycastHit, maxDistance, layerMask)) { // The raycast was out of bounds. return null; @@ -4004,7 +4003,7 @@ public bool TryGetComponent(Type type, out T component) /// Gets the player hitbox currently looking at if any. /// /// The max distance the raycast can reach. - /// if any + /// if any. public HitboxIdentity GetRaycastedHitbox(float maxDistance) { return GetRaycast(maxDistance, LayerMasks.Hitbox)?.collider.gameObject.GetComponent(); From 9cea31060d91fbd144fce245cad6a0122c86ca6f Mon Sep 17 00:00:00 2001 From: Saskyc Date: Fri, 27 Mar 2026 08:13:31 +0100 Subject: [PATCH 4/4] Minimal change. GetRaycastedPlayer now uses Layermask as Hitbox instead of "Player" as Yamato suggested --- EXILED/Exiled.API/Features/Player.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EXILED/Exiled.API/Features/Player.cs b/EXILED/Exiled.API/Features/Player.cs index a2cb7de65..2c005a3d2 100644 --- a/EXILED/Exiled.API/Features/Player.cs +++ b/EXILED/Exiled.API/Features/Player.cs @@ -4015,7 +4015,7 @@ public HitboxIdentity GetRaycastedHitbox(float maxDistance) /// The max distance the raycast can reach. /// if any. public Player GetRaycastedPlayer(float maxDistance) => - Get(GetRaycast(maxDistance, LayerMasks.Player)?.collider); + Get(GetRaycast(maxDistance, LayerMasks.Hitbox)?.collider); /// public bool HasComponent(bool depthInheritance = false) => depthInheritance