on this code i wanted to calculate the direction of where is the player and go against it but it doesn't work because it goes only to the right even if i am aproching the detector on the left side, can anyone help me pls?
`extends CharacterBody2D
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
var player
var chase = false
var SPEED = 50
func _physics_process(delta):
velocity.y += gravity * delta
if chase == true:
get_node("AnimatedSprite2D").play("Jump")
player = $"../../Player/player"
var direction = (player.position - self.position).normalized()
print (direction)
if direction.x > 0:
get_node("AnimatedSprite2D").flip_h = true
else:
get_node("AnimatedSprite2D").flip_h = false
velocity.x = direction.x * SPEED
else:
get_node("AnimatedSprite2D").play("Idle")
velocity.x = 0
move_and_slide()
func _on_player_detection_body_entered(body):
if body.name == "Player":
chase = true
func _on_player_detection_body_exited(body):
if body.name == "Player":
chase = false
`
https://clipchamp.com/watch/hVNFm67PIIT