Enemy warping instead of moving

Godot Version

4.2.2 -stable

Question

Hello everyone,
I am working on a state machine that will let my enemy walk around. Just from left to right, untill it detects the player. I am trying this Code so far:

func getMovement(move):
	if move == "left":
		velocity.x = speed
		animation.play("walk")
		animation.flip_h = false
	elif move == "right":
		velocity.x = -speed
		animation.play("walk")
		animation.flip_h = true
	else:
		animation.play("idle")
	
	move_and_slide()

but instead of moving, it is just warping around. I tied all kinds of speed values, none works. The process of choosing is made by an timer, that, every 5 seconds picks either “left” or “right” from an array.

Can somebody spot my mistake? Because I can´t, after over an hour.
Thank you.

you shouldnt put move_and_slide() only when you getMovement(move)
move_and_slide() should be called on every frame of _physics_process(delta)

1 Like

oh boy… that fixed it. How could I have not seen that?!
thank you very much!

1 Like