I’m a newbie, trying to make a platformer game. I’ve done the platformer tutorial, it works as expected, and now I’m making another one, a bit more advanced. I want the player sprite to change it’s animation when standing close to an enemy. I tried doing it with the “distance between two objects” so if player is standing closer to the monster than 100 px, the animation changes from regular to scared. It seems to work, except that it doesn’t play the whole animation only the first frame. The animation works in it’s preview and even if I assign it to another condition, so the problem must be with the condition. I’m not sure if this is a bug or I did something wrong, so please help.
The problem is that the “player is not moving” event sets two different animations, so the scare_monster animation doesn’t finish before it is set back to idle_spider again in the next loop through the events (which happens 60 times a second).
There are a few ways you could get around this, but perhaps the simplest is to add an additional condition to the “player is not moving” event to check whether the animation is already on scare_monster and don’t change it if it is. This would be done as an inverted condition where you are actually checking that the animation isn’t scare_monster. You can find the condition in Sprite>Animations and images>Current animation name.
This approach won’t work well if the spider can walk away from the player, because the animation won’t change back to idle_spider if it does. If that’s a possibility then it would be better to have two sub-events of the “player is not moving” event - the existing one that checks if the player is less than 100 pixels away and a new one that checks if they are more than 100 pixels away. You would then move the set to idle_spider action into the new sub-event.