[SOLVED] Top-Down A.I.'s spritesheet animation stuttering and/or freezing

Hello there,

I’ve reached a bump with my ennemy A.I.'s ( Red character) movement animation using the Spritesheet Extension:

It kinda works but as can be seen on the video it stutters or freezes when choosing between going one angle or the other while following the Player ( Blue Character).

Has anyone any idea on how to improve this ?

Video file of the problem:

Game File:

The A.I.'s movement code:

So watching a pathfinding behaviour exemple with a tank that paints in real time its path, I got to thinking I could try applying that code to my enemy AI to see if I could see what was going on. Surprise ! It showed that the Raycast is checking every frame (I think) where the Player sprite is, and its ray isn’t landing at the same point of the sprite, hence updating and changing the path of the enemy. So it’s not the animation code that was bad (although I rewrote that in a more straightforward way), it was the constant casting of the Raycast and changing of its goal position that was causing the animation to jitter between say, Right movement and Right/Up movement.

By adding a timer (2 seconds in this case) I slowed down the casting of the enemy’s ray and thus got a stable pathway for its movement.

Making it also more resource friendly !