I was following DevWorm’s top down rpg tutorial on youtube and for animations i wanted to make the enemy play different animation when it moves to some certain angles like if x and y both above 10 some sort of 45 ish degree angle, it will play side walk animation but if its above some angle or x y value it will play top or down talking animation. I couldnt find a way to do it and i hope i could explain my problem
This is the code
extends CharacterBody2D
var speed = 200
var player_chase = false
var player = null
func _physics_process(delta):
if player_chase:
position += (player.position - position)/speed
if position.y < player.position.y+5:
$AnimatedSprite2D.play("front_walk")
elif position.y > player.position.y-5:
$AnimatedSprite2D.play("back_walk")
else:
$AnimatedSprite2D.play("front_idle")
else:
$AnimatedSprite2D.play("front_idle")
func _on_detection_area_body_entered(body):
player = body
player_chase = true
func _on_detection_area_body_exited(body):
player = null
player_chase = false