The enemy is not constantly attacking

Godot v4.4

Hello, I’m trying to make a simple game where the player protects a planet by shooting the asteroids but, when I try to play the asteriods just get stuck and won’t try to hit the planet. The planet moves at a constant speed then after a certain time it stops then returns to it’s normal speed

My asteroid code:

extends CharacterBody2D

@onready var planet = get_node("/root/game/Planet")
@onready var ship = get_node("/root/game/Ship")

var entered : bool
var speed : int = 1100
var direction : Vector2
var extra : int = 2

func _ready() -> void:
	
	entered = false
	var dist = ship.position - position
	direction.x = dist.x
	direction.y = dist.y
	
func _physics_process(delta: float) -> void:
	if entered:
		direction = (planet.position - position)
	direction = direction.normalized()
	velocity = direction * speed * extra
	move_and_slide()


func _on_entrance_timer_timeout() -> void:
	entered = true

Any help will be appreciated, Thank you!

You haven’t included whatever is calling the entrance timer, so it’s hard to be sure, but it looks like initially (from what you have in _ready()), the asteroid will have its direction set to “towards the ship”. At some point (when the timer elapses) it will change direction to “towards the planet”.

Are you sure the timer is firing? Maybe put something in there to help you tell, like:

func _on_entrance_timer_timeout() -> void:
    entered = true
    self_modulate = Color(0xFF0000FF) # Turn red!

Or you could put a print() in or something, but the idea is, build in some debug scaffolding so you can see what things think they are doing. You could even put a label on the asteroid and stick text in it to indicate what it’s “thinking”.