Layer mask fix

This commit is contained in:
SDraw 2023-07-29 12:19:22 +03:00
parent 7161e65e3f
commit 46ed669e66
No known key found for this signature in database
GPG key ID: BB95B4DAB2BB8BB5

View file

@ -86,11 +86,14 @@ namespace ml_pmc
if((p_source != null) && (p_target != null))
{
Ray l_ray = new Ray();
l_ray.origin = (p_source.transform.position + p_source.transform.rotation * p_source.center);
l_ray.direction = (p_target.transform.position + p_target.transform.rotation * p_target.center) - l_ray.origin;
List<RaycastHit> l_hits = Physics.RaycastAll(l_ray, p_limit, LayerMask.NameToLayer("UI Internal")).ToList();
l_ray.origin = p_source.bounds.center;
l_ray.direction = p_target.bounds.center - l_ray.origin;
List<RaycastHit> l_hits = Physics.RaycastAll(l_ray, p_limit).ToList();
if(l_hits.Count > 0)
{
l_hits.RemoveAll(hit => hit.collider.gameObject.layer == LayerMask.NameToLayer("UI Internal")); // Somehow layer mask in RaycastAll just ignores players entirely
l_hits.RemoveAll(hit => hit.collider.gameObject.layer == LayerMask.NameToLayer("PlayerLocal"));
l_hits.RemoveAll(hit => hit.collider.gameObject.layer == LayerMask.NameToLayer("PlayerClone"));
l_hits.Sort((a, b) => ((a.distance < b.distance) ? -1 : 1));
l_result = (l_hits.First().collider.gameObject.transform.root == p_target.transform.root);
}