Considering moving obstacles


in my 2D Game everything is fine with my static walls. So my character is moving correctly to the target.

But when i put other moving obstacles or enemies in the scene, the character still tries to walk his ordinary way without considering the obstacles and get stuck when reaching anything. I try to work with an dynamic Rigidbody for the character for to use the physics of Unity …

How can i get the character to mention moving enemies and recalculating a better way to avoid getting stucked ?

There are a few different things you could do, but first consider if you really need physics for you’re characters, it can be a world of hurt.


you could add a raycast modifier to the path, so that it checks if anything is in the way.

you could look into rvo and see if that would solve some issues, in the past it has had in it’s own issues but it could very well be a lot more stable now.


If you need moving obstacles I would recommend reading this page:
For your use case I think just adding the DynamicGridObstacle component to your moving obstacles should work fine.
There is an example of the DynamicGridObstacle in the scene Example2_Terrain in the package.

As for avoiding agents. This is usually best done using some kind of local avoidance, not using pathfinding.
There is an example of this in the scene “Example16_RVO 2D”. This will only grant you very local avoidance however, the agents will not plan new paths to avoid crowded areas for example.