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!