0 votes

I have been working on a small project with enemies who will be able to pathfind around objects, and etc. I plan to have multiple enemies on the screen at one time, so I have the enemy scene instanced. The problem I am running into, is the fact that I cannot (as far as I am aware), use the Navigation2D node outside of the enemy scene. However, I cannot place the NavigationPolygonInstance in the enemy scene, because I would not be able to create it inside of my game world. This of course conflicts with the need for the NavigationPolygonInstance to be a child of the Navigation2D.

Any help would be greatly appreciated!

in Engine by (12 points)

1 Answer

0 votes

Why can't you have your Navigation/Polygon as a part of the world your enemies are pathfinding around? I'm not even sure how it would work to have the navigation on the enemies..

All you need is to have some function on your enemy that references their world (assume the enemy is a direct child of the world), and returns the path from their position to wherever they're aiming for.

(on the world)

func find_path_to_player(from_pos, to_pos):
    return get_node('Navigation').get_simple_path(from_pos,to_pos)

(on the enemy)

func get_path(to_point):
    path = get_parent().find_path(self.get_pos(), to_point)

From there, the enemy gets its path and figures out what to do with it from there.

by (1,328 points)
edited by

Hm.. I'll give it a shot, thanks!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.