var chase = false
var speed = 100 @onready var anim = $AnimatedSprite2D
func _physics_process(delta: float) → void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
var player = $"../../player/player1"
var direction = (player.position - self.position).normalized()
if chase == true:
velocity.x =direction.x * speed
anim.play("run")
else:
velocity.x = 0
anim.play("Idol")
if direction < 0:
$AnimatedSprite2D.flip_h = true
else :
$AnimatedSprite2D.flip_h = false
move_and_slide()
I created the mob behavior and when I was almost done there was only a part where it could turn but when I wrote that part when I started the game it started to crash the code itself and the part that was causing the crash are written in the question
When the game crashes, what line does it give you in the error code, and what is the error? At the bottom of the editor when the game crashes it should give you an error message in red.
The game crashes when there are these 4 lines in the code if direction < 0: $AnimatedSprite2D.flip_h = true else : $AnimatedSprite2D.flip_h = false
after the game crashes in console this error appears
invalid operands vector 2" and "int" in operator ">"
the error is that the game does not work because of the lines in the code that are responsible for turning the character sprite