How to make my enemy move every second or so then stop

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MothEater

Ok so I’ve finished a basic go right hit wall then turn enemy, but the thing is I want this enemy to move then, then move again since its a maggot and it scrunches but I can’t figure out how to do so.
I’ve tried using
if move_and_collide(Vector2.RIGHT):
yield(get_tree().create_timer(1.0), “timeout”)
But that makes it just stop when it changes direction not when every second.
And I can’t exactly figure out or understand the timer node for whatever reason.
This is my code currently, any help is appreciated :slight_smile:

extends KinematicBody2D
class_name Actor
const FLOOR_NORMAL: = Vector2.UP
export var speed: = Vector2(300.0, 1000.0)
export var gravity: = 3000.0
export var jump_speed = -800
var _velocity: = Vector2()
var jumping: = false
var jump_was_pressed: = false

extends “res://src/actors/”
export var score: = 100
func _ready() → void:
_velocity.x = -speed.x
func _on_StomptDetector_body_entered(body: PhysicsBody2D) → void:
if body.global_position.y > get_node(“StomptDetector”).global_position.y:
func _physics_process(delta: float) → void:
_velocity.y += gravity * delta
if is_on_wall() :
_velocity.x *= -1.0
_velocity.y = move_and_slide(_velocity, FLOOR_NORMAL).y
if move_and_collide(Vector2.RIGHT):
get_node(“enemy”).set_flip_h( false )
elif move_and_collide(Vector2.LEFT):
get_node(“enemy”).set_flip_h( true )
func die() → void:
PlayerData.score += score

use Node timer
use Signal (time_out)

var a = 0

func _on_Timer_timeout():
  a += 1
  if a == 1:
  elif a == 2:
// and last 
  elif a == 5:
	  a = 0

ramazan | 2022-02-15 07:11