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.
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?
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.