How do I make an enemy object perform a firing animation?

I want to delve deeper on animations on gdevelop but I’m currently stumped on how to make enemy object perform like a wind up animation before they fire a bullet, because my criteria for my enemy object to fire at the player is that the player just needs to get within a certain distance with the enemy and the enemy will start shooting, so my problem is how do people make enemies perform a fire animation then enemies wait awhile and during the wait time before the next shoot they will just walk around?

DEPNEDS

Answer to your question would vary dramatically depending on around what you would build your game logic
But generally in each case it could be adjusted

You could create timer for your enemies
But WAIT action will also work

And instead of opacity you could use some number variable but idea is you need to check some value for all engine cares you could even change and check object width
And i say why to create variable if you can just use opacity which is already there

For example
When enemy be in range in which he would start attacking

Condition
Enemy opacity = 255
Enemy is animation is NOT EQUAL TO windup

Action
Change enemy opacity set to 254
Change enemy animation set to windup

Condition
Enemy opacity = 254
Enemy animation is WINDUP
Animation of enemy is FINISHED

Action
Change enemy animation set to FIRE
And fire however you want

And last event
Condition
Enemy opacity = 254

Action
Change enemy opacity to 253
Wait how long you want
Change enemy opacity set to 255

So I think you should look into the concept of Finite State Machines. Basically, you need to consider the states of your enemy, or what your character is doing at that point, and tracking it. For example: idle, walk, wind up, attacking, damage and dead are some that I could imagine you using.

Once you have these planned out, create a variable to track the states, and then when the state is changed, assign an animation to that variable.

So for example, idle could be the default state. Maybe set a timer so that every so often, the enemy will pace around, so that timer will change the state to “walk”, which updates the animation.

1 Like

Could this be done without using variables? because I would like to keep it very simple. And I was thinking that instead of opacity, I was thinking of using the players distance to enemy instead. And is there an action that checks time like every X amount of seconds?

because if there is I was thinking that it would go like this

Condition
Player distance is less than X amount

Action
Enemy objects activate boids movement behavior

Condition
Every X seconds

Action
Set enemy object animation to windup

Condition
When enemy object windup animation is finished

Action
Enemy object fires bullets

Value is Value
You can check if object width is equal to 20
And in action set it to 20.000000000000000001

And so it is not anymore equal to 20
But now you can check is it equal to 20.000000000000000001

And change in size you will not notice
Same with opacity

As for time there is timer you can use for that

Distance between them is below some value

Opacity of object = 255

Change object opacity to 254
Start object timer
Change animation to windup

And then
Timer value is above some value

Delete timer
Change object opacity set to 255