public Cover GetCoverForPlayer(AgentHuman Agent, float distance) { Vector3 pos = Agent.Position; Vector3 coverdir = Agent.Forward; Cover c; for (int i = 0; i < Covers.Length; i++) { c = Covers[i]; //Debug.Log(Covers[i].name + " Angle:"+c.GetCoverDirAngle(coverdir)); if (c.GetCoverDirAngle(coverdir) <= 0.7f) { continue; } Vector3 dirToPos = (pos - c.Position).normalized; //Debug.Log(Covers[i].name + "dot: " + Vector3.Dot(c.Forward, dirToPos)); if (Vector3.Dot(c.Forward, dirToPos) > 0.0f) { continue; } //test if pos is on the cover edge Vector3 dir = c.RightEdge - c.LeftEdge; //edge float d = dir.magnitude; //edge distance dir.Normalize(); float dot = Vector3.Dot(dir, pos - c.LeftEdge); // get distance on edge //Debug.Log(Covers[i].name + " dot:" + dot + "cover len" + d); if (dot < -.3f || dot > d + .3f) { continue; } //Debug.Log(Covers[i].name + "distance: " + c.GetDistanceTo(pos)); Vector3 CoverPos = c.GetNearestPointOnCover(pos); float DistToCover = (CoverPos - pos).magnitude; if (DistToCover > distance) { continue; } if (c.IsLockedForPlayer(pos, Agent.CharacterRadius + Agent.BlackBoard.CoverSetup.MultiCoverSafeDist)) { // Debug.Log(Covers[i].name + " locked"); continue; } // test just ragdols LayerMask mask = ObjectLayerMask.Ragdoll; // there is nobody blocking agent's movement if (Agent.SweepTest((CoverPos - pos).normalized, DistToCover, mask)) { return(c); } } return(null); }