extends CharacterBody2D
@onready var progress_bar: ProgressBar = $ProgressBar
@onready var player = get_tree().get_root().get_node("/root/Game/Player")
var speed: float = 200
var Player_pos
var Target_pos
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
progress_bar.value = Global.enemyHits
func _process(delta: float) -> void:
progress_bar.value = Global.enemyHits
func _physics_process(delta: float) -> void:
Player_pos = player.global_position
Target_pos = (Player_pos - position).normalized()
if position.distance_to(Player_pos) > 3:
position += Target_pos * speed * delta
It doesn’t work and my game is in 2d. It just says I can’t use vector3 so I changed them to vector2 still doesn’t work and how does this fix my problem that the enemy is going to a weird position instead of the player.
mixing global positions with local positions is bad because your math is in different coordinate systems. I notice there isn’t any look_at calls or rotation changes so I’m surprised your first screenshot has rotational changes.