Forum rules - please read before posting.

2D Game - Block pathfinding temporarily?

Hello, I have a 2d game with polygon collider.

And I have a door that can be closed or opened by player. When door is closed I want to cut off access to a room behind the door. I used the Collision Cube 2D object to block the door entrance and it works in preventing the player from entering the place. But player is still trying to walk to a position behind the door. (Walking in one place next to door).

Is it possible to block the navigation like for 3d Navmesh? Or stop movement if area is unreachable?

Basically end result being that character wont walk in one place.

Comments

  • 2D pathfinding isn't collision-based, but instead uses the shape of the NavMesh's collider to work out where characters can and can't go. Placing down a collider will stop them getting past it, but won't stop them from attempting to.

    The way to go about this is to modify the NavMesh itself. It is possible to do it by adding a "hole" that sits along the boundary, but the easiest way is to swap out the NavMesh entirely.

    Duplicate your existing NavMesh and remove all the vertices in the blocked room, so that there's no way to enter it. Then, when the door is closed, use the Scene: Change setting Action to switch to this NavMesh instead.

  • Thank you. Two Navmeshes should do the trick nicely.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.