So the basic set up I have is an enemy that move toward the player and changes the animation animation based on Direction. The enemy’s wander state works perfectly as intended. The problem I’m having is when I switch to the attack state and use move_toward the animation kinda gets stuck in what ever I was playing regardless of where it is now moving. I was hoping for an idea as to why this is happening and maybe an idea of how to fix it. Any help would be much appreciated Ps I am including a photo of the relevant code ( var movedir = vector2(0,0))

A Vector is a floating point type. Not sure, but I would guess your match statement won't work because the value will never be exactly 1 or exactly 0. For example, you can set a float to "1" but in the computer it will actually be "1.00000001" or something like that. You can replace the match with a series of if statements. For example:

if movedir.x < -0.99:
    spritedir = "left"
elif movedir.x > 0.99:
   spritedir = "right"
# other if statements
$anim.play(spritedir)

Also, you should try to avoid checking for exact numbers. This line could cause a problem:

if movetimer == 0

It is better to always do something like this:

if movetimer <= 0

Since sometimes the values can keep going depending on the logic and then it will get stuck or never happen.

Movetimer is a manual count down that why it always always checks That aside your solution worked well. I was thinking I needed to run the animations separately from the wander state. I did have to modify it a little bit but over all I’m vary happy with it. Side note increasing the movedir.y to 50 gives me a greater area for the left and right animations to play ( incase some looks at this and has that question Ill attach an image of how I implement the code

2 years later