@onready var progress_bar: ProgressBar = $ProgressBar @onready var player = get_tree().get_root().get_node(“/root/Game/Player”)
var speed: float = 0.01
var Player_pos
var Target_pos
Called when the node enters the scene tree for the first time.
I would bet your enemy or player are not centered at their scene’s origin, could you show the enemy and player scene? Your math is also mixing global_position and position which could be problematic if your main scene is offset from it’s origin.
lerp is probably a bad function to call, especially on a CharacterBody2D. Your physics process function was closer to a good script, just make sure to use velocity and move_and_slide() as it’s a CharacterBody2D
func _physics_process(delta: float) -> void:
var difference: Vector3 = player.global_position - global_position
var direction: Vector3 = difference.normalized()
if difference.length() > 3:
velocity = direction * speed
else:
velocity = Vector3.ZERO
move_and_slide()