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

Attention Topic was automatically imported from the old Question2Answer platform.

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

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/Actor.gd”
export var score: = 100
set_physics_process(false)
_velocity.x = -speed.x
func _on_StomptDetector_body_entered(body: PhysicsBody2D) → void:
if body.global_position.y > get_node(“StomptDetector”).global_position.y:
return
die()
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:
queue_free()
PlayerData.score += score

use Node timer
use Signal (time_out)

example
var a = 0

``````func _on_Timer_timeout():
a += 1
if a == 1:
print("one")
elif a == 2:
print("two")
//elif.....
// and last
elif a == 5:
print("five")
a = 0
pass
``````

ramazan | 2022-02-15 07:11