2.5D enemy still in walking state instead of idle in animation-tree

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By RockyXDeadman

i am trying to program a 2.5d enemy and its giving some problems.

i have put an area2d around it to detect when player is nearby and chase him and attack him and when player is not in the area2d u go back to normal idle state. but my enemy when i leave the area2d keeps walking on same spot and doesnt go to idle state.

here is my code:

`extends KinematicBody2D

export var acceleration = 300
export var max_speed = 50
export var friction = 200

enum {
idle,
wander,
walk
}

var velocity = Vector2.ZERO
var state = walk

onready var playerdetectionzone = $playerdetectionzone
onready var animationplayer = $AnimationPlayer
onready var animationtree = $AnimationTree
onready var animationstate = animationtree.get(“parameters/playback”)

func _ready():
animationtree.active = true

func _physics_process(delta):
match state:
idle:
velocity = velocity.move_toward(Vector2.ZERO, friction * delta)
seek_player()
walk:
var player = playerdetectionzone.player
animationstate.travel(“walk”)
if player != null:
accelerate_towards_point(player.global_position,delta)
else:
state = idle
velocity = move_and_slide(velocity)

func accelerate_towards_point(point,delta):
var direction = global_position.direction_to(point)
velocity = velocity.move_toward(direction * max_speed, acceleration * delta)
animationtree.set(“parameters/walk/blend_position”,direction)

func seek_player():
if playerdetectionzone.can_see_player():
state = walk`