![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Skydome |
So I have managed to do pathfinding with navigation2d. But now I need to also do obstacle avoidance.
func Navigate():
if path.size()>0:
#print("Navigate")
#Enemy_Character is the Enemy AI using the navigation
Enemy_Character.velocity=Enemy_Character.global_position.direction_to(path[1])
if Enemy_Character.global_position==path[0]:
path.pop_front()
pass
func generate_path():
if nav2d!=null and Target!=null:
#print("Generate Path")
path= nav2d.get_simple_path(Enemy_Character.global_position, Target.global_position, false)
Enemy_Character.line2d.points=path
pass
So this navigation is working. But obstacles are not avoided. Obstacles like other enemy NPCs or magic barriers or ice barriers.
I have created 3 raycast 2ds to detect collision with other enemies and miscellaneous environment objects. But I don’t know what to do next. Like ok I detected the collision but now how do I generate a new path that avoids the collision.
I have looked at some obstacle avoidance. But they’re doing the navigation very differently. None of them use navigation 2d for starters. I have been working on a steering velocity. But it’s kind of not working.
Navigation and collision avoidance is a very new topic for me. .Any help would be appreciated.