Getting an Actor to Switch Animations Then Start Shooting


  • Posts: 57
Lately I've been trying to make a code where when the player gets close enough to the enemy, the enemy will switch to a surprise animation, and after the surprise animation is done, depending on where the player is, the enemy will start shooting a projectile at the player. I've only gotten the enemy to get to the surprise animation and then the animation keeps on repeating until the player isn't close to the enemy anymore. This is the code I have.

Electric Fruit

  • *
  • Posts: 111

I can see two areas I would look at:

1. Because you have this running in "when updating" the code is re-running constantly. I would look in to putting some kind of variable in place to run the code only once when the player enters firing range. Its important to make sure that you only trigger the "do in 6 seconds" block once so you'll need to put something like this to stop the code from rerunning once its triggered.

If "player is in range" = false
Set "player is in range" to True

and then run your animation and firing behavior.  You'll also need to put a check in place to see if the player leaves the firing range and reset the variable.

2. At the moment I don't think the shooting part of the behavior is running because the conditions are unlikely to ever be met. I would look at the following part

Set animation to Left Attack         
If current Animation = Left Attack
If current Frame for self = 4 and Shoot = False                             

I think the last line could be an issue you have just set the animation to left attack on the previous line which will set the frame to 0 and I don't think you've left enough time for the animation to run through to frame 4 so it will always return as false.

Hope it helps


  • Posts: 57
So I did make it so the code is triggered once and when the player is out of range it will reset the variable, but I don't follow your 2nd piece of advice because I am following a model similar to another enemy where they shoot on a certain frame. This is the code I have for the other enemy and it works.