Support Forum

2D AI stuck when going through doors

I’m using the latest free version for a 2D top down (not isometric) game. My AI is stuck at the door frame. See photos for full explanation.

problem 1
problem 2

My door can rotate according to the Vector2.right (this is my forward direction) of the AI. My problem is that the AI then becomes stuck at the door because it is blocking in its path. I can’t make the door’s flooring to be unwalkable as it should be walkable. Is there a way to bypass this problem without disabling the door’s colliders as I still need it to collide with other objects?

Hi

Well, you either need to make the walkable surface of the navmesh actually correspond to the walkable surface (i.e. the area under the door should be unwalkable) or the agents need to be able to pass through the door. Otherwise you will end up with this situation.

If you have a custom movement script I suppose you could run some raycasts to make the agent additionally steer away from things blocking its path, but that solution does require some work.

I intend to do everything without having a bunch of raycast as this would be tedious.

I’m currently using a grid base graph for the game. Though looking at the navmesh suggestion, I am unsure on updating the mesh according to the door’s position. is there an option to mask out certain parts using sprite shape dynamically?

For the suggestion of agents being able to pass the door, do you mean I will ignore collision for the agents and the door? This is simpler as I could easily change the layer of the door. Downside is that it may lead to unintended bugs.

Yes

A grid graph is also a kind of navmesh, I didn’t suggest using the graph called “navmesh graph” itself. Sorry for being confusing.