Mob getting stuck and jittering on seemingly nothing

Godot Version

v4.2.2.stable.official [15073afe3]

Question

I am new to godot and trying to me a TD game. I have a basic mob circle that walks down the path towards the gate however it gets stuck and starts jittering back and forth in the same spot.




Here is the code I’m using to make the mob move. I have a little target set on the wall as a character2D for the mob to target and chase but it gets stuck at that point in the screenshot. Please let me know if you need to see anything else to help I am beyond lost at the moment.

If you upload your project to github, I will run it and take a look.

I would appreciate it though it’s definitely a bit of mess of different tutorials I’m trying to learn from just to figure everything out. Would you mind telling me how I would go about uploading it to github for you?

1 Like

Make free github account.

Get github desktop.

Create a repo in github desktop out of the root folder of your project.

Somewhere you can indicate you are using gdscript

Then starting with step 3 of the following link, upload that repo to github

I think I did this right, GitHub - LunarGamer/TowerDefenseGame

Looks good. I will try to check it out by tomorrow.

Hi were you able to figure out what the cause might be?

Been busy, but I will sit down right now and take a look.

Okay thank you take your time I’m patient so don’t worry!

The biggest problems are that your objects arent where you think they are. When you click an object in the 2D preview and move it, you arent moving the object, but just a child node that represents the visuals. I make this mistake all the time because “click and drag” is ingrained. You need to select the object in the scene tree, then change from the “select” tool (arrow) to “move” tool (plus shaped intersecting arrows) - that way you just move the thing you intend to instead of selecting a visible sub node.

You could see this immediately if you turn on the debugging on the navigation agent (see red box in the bottom right of first screen shot above). What you would see is a seemingly randomly placed line get smaller and smaller. The two ends of that line are where your enemy and target actually are…not the visual sub nodes.

After I fixed things by resetting transforms on sub nodes and transforming (moving) only the intended node (like the characterbody), things worked. I also made a new target while I was figuring this all out.

The dancing is caused by overshooting the target then trying to navigate “back” to it and over shooting it again.

The agent is stuck dancing between two positions

This is usually caused by very frequent path updates every single frame, either deliberate or by accident (e.g. max path distance set too short). The pathfinding needs to find the closest position that are valid on navigation mesh. If a new path is requested every single frame the first path positions might end up switching constantly in front and behind the agent’s current position, causing it to dance between the two positions.

Ah ok that makes sense I will have to be mindful of that in the future. Thank you for such a detailed answer I really appreciate it.

1 Like

Glad I could help :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.