0 votes

Hey there,

Firstly I'd like to say that I'm still very new to this engine and I am experimenting with some of the 2D functionality. I found myself at a bit of a roadblock that had me scratching my head all night. Keep in mind my code is a bit messy as I have been, like I said, experimenting with GDScript.

Here is a clip of the issue: https://i.gyazo.com/f7c9d00bd1f806ab93b45e1b405a4390.mp4

As you can see the enemy AI gets completely while trying to navigate the generated path between itself and the player. My best guess at what is causing this is that I am generating a new path for every tick which is causing the enemy to get stuck. However, after further investigation, that doesn't seem to be the case. Also, my tilemap is set up correctly so that is not something that needs to be considered either.

Below I have posted the pastebins relating to the enemy's AI.
Enemy.gd: https://pastebin.com/WxrqpGNf
EnemySM.gd: https://pastebin.com/YZRXW8n8
StateMachine.gd: https://pastebin.com/qdk5b2dd

Thank you for your help in advance!

in Engine by (32 points)

2 Answers

0 votes

did you tried latest beta builds?

by (73 points)

No, but I'm on version 3.4.4 stable build. Do the newest beta builds describe any changes to the Navigation2D functionality?

dunno, i could read all 3 betas changelog list and search for navigation2d changes and make list functionality changes for you. But you could just download and try.

+2 votes

I had encountered this problem once before, in my case I wasn't using the points in the navigation array properly,

Assuming you've a similar setup where you create a list/array of points from the enemy node to you player node called path

what you need to do in your Enemy.gd script at line 31:

instead of equating the position of your character and first position in the path (path[0]):

if global_position == path[0]:

change it to something like this:

if global_position.distance_to(path[0]) < 1:

This checks if the distance between the Enemy node and the path[0] point is less than 1

From my intuition this weird thing happens would be because somehow the engine misses the point where global_position == path[0] and doesn't remove the path[0] so your character just keeps chasing the path[0] which hasn't been removed yet and gets stuck there.

Here's a repo where I built my firest Godot game using these techniques you can have a look at it if you'd like:
https://github.com/1MochaChan1/scares

by (53 points)

Hey!

Thanks for your help, I tried that out and completely recoded everything and this is what the script looks like now: https://pastebin.com/857bjymk

Unfortunately, it still hasn't solved the issue, can you spot anything that looks like it could be causing the problem?

Again, thank you very much for the help!

can you check if the point is being removed from the array?
because other than that there shouldn't be any reason for the node to get stuck in the same place.

Also if you haven't done it already I would suggest that you play with the threshold value a little bit.

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 webmaster@godotengine.org with your username.