- Home /
OffMesh Link and NavMesh Obstacle
I have two navmeshes connected by OffMesh Link.
Those NavMeshes are in seperate rooms and there is a door between them. The door is a NavMesh Obstacle.
Off Link is right through the middle of the door
If I set a destination to the other side of the door, my agent just jumps through the link and through the door.
Here is the screen from my simple test scene, I hope it's clear enough
My question is: is it possible to block an off mesh link if there is an obstacle in the way?
I will probably be using custom script to traverse the link with regular speed so I can throw some code in there if someone could tip me how to do it.
Answer by Casiell · Jan 04, 2019 at 09:51 AM
Ok, so I have kind of an answer for this right now.
In Update I check if NavMeshAgent.isOnOffMeshLink. If it is, then I start a coroutine to traverse it manually with regular speed, but before it, I can do something like this:
OffMeshLinkData data = agent.currentOffMeshLinkData;
Ray ray = new Ray(data.startPos, data.endPos);
var hits = Physics.RaycastAll(ray);
if (hits.Any(hit => hit.collider.GetComponent<NavMeshObstacle>()))
{
_agent.Warp(_agent.transform.position);
yield break;
}
I'm not a big fan of _agent.Warp, but I have to get off the link somehow and this is the only way I found for now.
I will not mark this as answer, because I feel like it's hacky and there should be a better way, but I will leave this here anyway