It sounds like resetting “enemy_move_possible” inside the _process function caused the movement to stop altogether, likely because it was reset too quickly, preventing any visible movement…well…try this
extends Area2D
@onready var enemy_object = $“.” # Mabye this refers to the correct node
@onready var enemy_movement_cooldown_timer = $enemy_movement_cooldown_timer
var enemy_speed = 100
var enemy_random_value = 0
var enemy_move_possible = false
func _ready() → void:
enemy_random_value = pick_random_position()
enemy_movement_cooldown_timer.start()
func _on_enemy_movement_cooldown_timer_timeout() → void:
enemy_random_value = pick_random_position()
enemy_move_possible = true
print(“time out”)
func _process(delta: float) → void:
if enemy_move_possible:
enemy_object.global_position = enemy_object.global_position.move_toward(Vector2(enemy_random_value, 98), delta * enemy_speed)
if enemy_object.global_position.distance_to(Vector2(enemy_random_value, 98)) < 1:
enemy_move_possible = false
enemy_movement_cooldown_timer.start()
func pick_random_position() → int:
var enemy_coord = [-127, -100, -90, -78, -62, -48, -28, -10, 0, 9, 12, 26, 40, 63, 72, 99, 102, 130]
return enemy_coord.pick_random()
Movement Control:
“enemy_move_possible” is only set to “true” when the timer times out.
The enemy moves toward a random position, and once it gets close enough (within a distance of 1 unit), movement stops (“enemy_move_possible” = “false”), and the timer restarts.
Timer and Movement:
Each time the timer times out, a new random position is selected.
The movement happens over multiple frames, based on the delta time, so it’s smooth and visible.
Movement Completion:
The enemy stops moving when it reaches (or is very close to) the target position, and the process repeats with the timer.
This approach should allow your enemy to move every 10 seconds as desired, with smooth and controlled movement.
Let me know if this helped …
oh wait its already solved… my bad