How do I make an enemy slide

Hello!
I’m making a game which requires a mechanic where you step on an enemy, it flips on its head, and then if you walk into it on either side it will slide in that direction, killing any other enemies it collides with. Think Mario when he steps on a koopa, it goes in its shell and then you can knock its shell etc. (I don’t need mine to go in a shell, just to flip on its head and then slide).

So far, when you step on the enemy, it flips on its head. When it collides with you, you die. That’s all the code i have managed to figure out on my own.

Heres my code, and my explanations lol.

You need another variable and make it number var
Call it Sliding

Now when BadGuy var IsFlipped = true
Player is in collision with BadGuy
And now you need 2 SUB events
1st Trigger once
Player.CenterX() is LESS THAN BadGuy.CenterX()
Action set BadGuy variable Sliding to 1

2nd Trigger once
Player.CenterX() is GREATER TAHN BadGuy.CenterX()
Action set BadGuy variable Sliding to 2

NOW separate 2 events
BadGuy variable IsFlipped = true
BadGuy variable Sliding = 1
Action simulate pressing LEFT for BadGuy

2nd event
BadGuy variable IsFlipped = true
BadGuy variable Sliding = 2
Action simulate pressing RIGHT for BadGuy

Thank you so much for your help! I believe I have copied your code, and it worked (sort of?) if you don’t mind, ive attached my code and the error. Sorry, it won’t allow me to attach more than one photo because I’m new… so I made you a photo collage lol as I think a visual would help explain.
when I step on the bad guy, he flips, and then after I knock him…he just follows me around, like, on top of my character as if he’s stuck inside. He bumps from left to right within my character as if he’s being knocked both ways, and then and I jump out of the way he goes in whichever direction he was bumped inside me last. Please forgive me if this is an error on my end, I’m rather new to coding.could you please tell me what I can do to stop this? Thank you SO much!

Switch

Ah, I see! It worked!! Thank you so much. Silly me. Thank you, you’ve been so helpful and I appreciate your fast response time :smile:

1 Like