Enemy not moving at all

Godot Version

Godot 4.6.2 Steam Stable

Question

I have an enemy that Is able to target the player using State Charts, but doesn't move from the area that they start with. I am very new with Godot, so ask me any questions you have and I'll try to answer it to the best of my ability. I am also using a tutorial for the enemy script: https://www.youtube.com/watch?v=4DItltKD_LA&t=49s

(How embarressing that I can't follow a tutorial)

You need the set the velocity in the process function. Right now you only set velocity if enemy is not on floor.

I pretty sure the the velocity being set while the enemy is not on the floor is for the gravity. If it were placed in the process function, i think that the gravity would only be applied when the player enters the enemies CollisionShape. Correct me if I’m wrong, since I’m really new.

Or are you saying that i should set a different velocity for the horizontal movement inside the process function, because that would make more sense.

The screenshots of the current script are an extension of a separate script, so I’ll send a screenshot of it when I can

this is the script that the enemy script extends from

Doesn’t look like your changing velocity much in _physics_process, only applying gravity. Can’t speak to the state machine plugin you are using, are you sure it’s signal is connected like in the video?


Instead of screenshots it’s best to paste scripts as text, between three ticks for a block of code

Yeah, I remember debugging the State Charts to see if they were causing issues, and to me they looked fine. The code on the lines 66 - 68 have the enemy face the player once they enter the “toFollow” state, and those lines of code are working fine.

# Rotate to face movement direction
	#(Remove if you want enemy to always face you)
	if direction.length() > 0.01:
		var target_rotation = atan2(direction.x, direction.z)
		rotation.y = lerp_angle(rotation.y, target_rotation, 5.0 * delta)

The NavigationAgent3D debugger also shows a line going from the enemy to the player, which I assume is the path that the enemy would take to get to the player, the only thing is that the enemy isn’t moving. If I need to, I can check the states again.

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