How do I fix this enemy animation change and bullet firing event?

How do I…

Fix this issue where my enemy character stays in the default ‘idle’ animation despite having the event to change it’s animation to ‘walk’ when it moves. I also have issue with the enemy not finishing it’s attack animation (stuck in frame 1), resulting in the enemy not firing it’s bullets towards the player. I’ve tried changing the attack animation to only 1 frame but it still refuse to fire it’s bullets, I assume because the game still doesn’t count it as the animation being finished for some reason?

What is the expected result

The enemy is standing still and flipping horizontally every two seconds using the timer event. When it sees the player with raycast, it chase the player until it gets to about 75 pixel away from the player then it stops. After stopping at this position, the enemy change it’s animation to ‘attack’ which resulted in it firing bullets towards the player’s last seen position.

What is the actual result

What works:

  1. Enemy flipping every 2 seconds with timer event.
  2. Pausing the timer event when the enemy is not standing still.
  3. Detect the player with raycast and chase them with the add force action.
  4. Stopping the chase when it’s 75 pixel away from the player.
  5. Changing it’s animation to ‘attack’.
  6. Changing it’s animation back to ‘idle’ when it’s not detecting the player.

What doesn’t work:

  1. Changing the enemy animation from ‘idle’ to ‘walk’.
  2. Finishing it’s ‘attack’ animation so it can fire it’s bullets.

Related screenshots

Video on how it looks in game

It’s only 2 MB, you can view it on browser without downloading it.

supposing Mafia thug is moving to the player…
it means that it’s flipped or not…so it’s impossible to set the walk animation.
bcs one of the flip conditions is always true and when your character get to said x position animation doesn’t swap.

Also mafia is stopped override your attack animation, bcs you said
stop mafia --set animation to attack…(which unpause the timer!)…which stack with mafia is stopped–set animation to idle…

Ahh… I see. I tried disabling the Mafia_Thug is stopped event and the firing started working. From the way you explain it, I assume that means a lot of my events are clashing with each other? Is it possible to adjust each one or would it be easier if I just rework the whole thing?

I’d say you’re not doing badly, the problem is that you need to reorganize things a little.
Double‑check your timer, maybe using a text debug, since it’s difficult to track.

A better approach: try handling one direction first, then add the other.
If both conflict, you could fix it with a turn variable for the enemy but only as last resort.

Painful part of animations that you are about to learn is that you cannot just tell animations to change

Like you cannot allow something to happen
You also need to prevent it from happening when you don’t need it

Look at your very 1st event
Mafia thug is stopped change animation to idle

2nd event
Mafia thug is moving change animation to walk

Now let’s look at this

To my understanding
You are changing animation to attack
Raycast hit something and when X position of mafia thug is greater than player X

Looking at that screenshot at what i marked in red
Can you tell me which animation should play if mafia thug X pos is greater than player x and when raycast hits player?
I mean obviously attack animation

But can you now look at your 1st event
And at events i marked on screenshot and tell me which animation should play
When mafia thug is not moving and its X pos is greater than player X and raycast hits player?

OR same question but looking at 2nd event and what i marked in red
When mafia thug is moving and hix X position is grater than player X and raycast hits player
Which animation should play?

Now you see the issue?
You allowed more than 1 animation to play at the same time
They are literally fighting for a right to be played like we both try to go trough doors at the same time of width that could only contain one of us
And none of us is getting trough

You would need in your 2 top events condition to check that this raycast did not hit player i guess

ALSO you should not use action to check X position of mafia thug
But there is also condition to check CENTER X of object
That is what you should use
And then not Player.X() - 75
But Player.CenterX() and i guess now you would not need that -75

lol…i was imagining the scene

EDIT
Oh your quote was referring to imagining going trough doors not fighting

=============

As stupid as it sound

Tell me that is not literally what is going on
Like LITERALLY they actually are fighting for right to be played

1 Like

Got it. Maybe I should use variables to determine the enemy’s state then?
So instead of changing the enemy’s animation solely from whether or not it’s moving or the horizontal flips, It will check whether the variable (for example boolean variables called chasing / attacking/ idling) are true or false.
Therefore the animations aren’t “fighting to get through the doors” lol.

Variable state is just adding extra stuff on top
Unless you gonna do A LOT more complex logic for mafia thug
Then i would not see any point of using variables

BTW with variable you will be wondering why your variable is not changing instead of only animation

BUT you can try it if you want
Maybe you will be able to manage it better with it

From my experience, I’d begin with the raycast as the primary condition, since it already includes distance as an input,so it makes sense to use it.
just throwing some inputs…but as long as you find a method that works for you, you’ll be fine.

like
raycast to player–
-flip by raycast to player angle–
chase at desired distance…

On top on what RMDB wrote above
Do not invert raycast condition

Use NOT statement instead

Well, this has been quite a journey. :sweat_smile:

The animation changing issue
I indeed manage to fix it by using variables. Unfortunately when I begin working on the flipping event, the raycast somehow messed the animation and chasing action.

Raycast and horizontal flip issue
I ended up removing the raycast and use a custom sprite in the shape of a cone that functions as the enemy’s field of view. I have to stick it on a custom point, but I also have to readjust the placement whenever the sprite flipped. I use variable and timer to determine the flip condition and action.

Bullet firing event issue
I was using the fire bullets extension which works fine, but the reload wouldn’t work no matter how many times I tried adjusting the behavior and event (I probably just don’t understand how the extension works). Ticking the unlimited ammo option technically fixes the issue but I don’t want the enemy to shoot continuously. So I completely remove the extension and made my own bullet firing and reloading event, which means I have to make even more variables and timers to determine the ammo, cooldown, and reload.

Result

I fixed all the issue and the enemy works as I intended, but I made so many changes that it ended up being a massive rework rather than a simple fix. I’m sure there are more efficient ways to do this, but at least I know exactly everything that’s happening in my events sheet and I can easily customize it again later if I want to.

Screenshots

In case someone in the future encounter the same or similar problem as me and found this thread, here’s some screenshots of what things looks like in my project. I hope it helps. :wave: