r/unity_tutorials • • Feb 21 '23

Video NavMeshAgents lag behind player when chasing? Make them calculate an intercept course based on the player's historical velocity for more aggressive chasing AI!

146 Upvotes

1 comment sorted by

4

u/LlamAcademyOfficial Feb 21 '23

Full Tutorial on YouTube

Hey all 👋! Happy #TutorialTuesday!

In my game I noticed my zombies were a little too dumb, always lagging behind the player. I worked around that a little by having random spawns all around the level. That worked "okay" because it was relatively challenging to avoid the zombies coming from all sides. Eventually, you could still tell they were moving to a point slightly behind the player.

This week you can learn how to have NavMeshAgents calculate an intercept course to better chase the player. We'll use the historical velocity of the player, project it forward, and calculate a path to that location. Make sure to also check the agent isn't just running in front of the player by adding a Dot Product check!

👨‍💻 As always, the full project code is available on GitHub!