Direction stays as 0,0

version 4.2.2

Hello, I’m trying to make an enemy that approches the player. I have a direction variable, but every time I run the game the direction keeps staying as 0,0 even if I move the player. Therefor the enemy stays still. Here is my script for the enemy:

extends CharacterBody2D
var InRange = false
#@onready var player
@onready var player = get_node(“/root/Game/player”)
const SPEED = 300
func _physics_process(delta):
if InRange == true:
print(“in Range”)
var direction = global_position.direction_to(player.global_position)
print(direction)
velocity = direction * SPEED
move_and_slide()

func _on_area_2d_body_entered(body):
player = body
InRange = true

  1. Is signal connected?
  2. player = body line - shouldn’t it be if body == player or something?

hi, I have already found the problem, but still thanks!

1 Like