• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Jumping on enemy heads

B

Braeden Hammill

Guest
I'm trying to add a feature to my game where if you jump on the head of an enemy, you kill it. (like in Mario) I've only been "coding" for a few months and am not sure where to start. Any tips?
 

samspade

Member
It depends upon how your other code is set up and how precise you want to be. For example, if you use the 'standard' custom collision system from Shuan Spalding, Heartbeast and so on, you can make your enemy a child of your solid parent, in the step event you then you can check to see if the player is standing on an enemy, exactly as you would check to see if they are standing on the floor, and then apply a bounce force. You can make this method more precise by saving vsp (as vsp gets set to 0 when it collides) and using vsp to calculate the bounce force.

The downside to the above method is it prevents you from walking into an enemy from other directions (something you generally want to do in Mario like games). There are ways around this (e.g. you treat enemies like a pass through platform that only registers collisions traveling down), but another solution is you check for a collision and whether you're falling (vsp > 0) and, if found, you reverse vsp (vsp = -1). Assuming square masks, this works pretty good.
 
Top