Unity3D Navigation: My nav agent gets stuck. How to make him smarter?

Started by
2 comments, last by babaliaris 3 years, 4 months ago

Check this video to see what is going on:


In general, I have some trouble making my nav agent smart. Currently, in order to open a door, my logic says "If the agent distance between him and the door < 4 && he's looking at the door, then open the door."

If the agent tries to open the door from the inside, then this logic works perfectly. He just pushes the door. But in this case, where the agent tries to open the door from the opposite direction (he must pull the door), sometimes he gets stuck.

Basically, if someone can tell me how to to make the agent open the door from a distance where the door will open before the player can reach it (so it won't hit him or block him) AND at the same time the agent is smart enough to not open nearby doors that he is not supposed to open, then this is exactly what I'm trying to achieve.

The reason that I also check “If the agent is looking at the door” is to prevent him from opening doors that he is not supposed to. For example, he might pass next to a door but 90% of when he passes next to a door he's actually not looking at it, so the door is not opening. This is why I implemented it like that. But of course, there is still a possibility that he might be close to the door and looking at it while he's not intended to open the door.

Thank you!


void life()
{
  while (!succeed())
    try_again();

  die_happily();
}

 

Advertisement

One quick solution is to put an invisible object that blocks the generation of the navmesh on the bad side of the door. Of course, that will also keep people from sliding the walls past the door… but it is, again, a quick solution.

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

IADaveMark said:

One quick solution is to put an invisible object that blocks the generation of the navmesh on the bad side of the door. Of course, that will also keep people from sliding the walls past the door… but it is, again, a quick solution.

Actually, this is awesome! If that object is a NavMeshObstacle with the carve option enabled, I can even enable and disable that obstacle at runtime and the path will be updated automatically!


void life()
{
  while (!succeed())
    try_again();

  die_happily();
}

 

This topic is closed to new replies.

Advertisement