• 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!

How do you make a knockback effect?

Kyndle

Member
I've been trying to make the player get knocked back when they get hit. So I want the player to fly back like in Zelda 2, Shovel Knight or Castlevania games, and same for some enemies. So when I collide with an enemy it puts me in hit state. I've looked up a bunch of tutorials and can't really get it right.
Code:
sprite_index = spr_knight_hit;

var vsp_max_final = vsp_max;
var grv_final = grv;

vsp += grv_final
vsp = clamp(vsp, -vsp_max_final, vsp_max_final);

hsp = sign(x - obj_player.x) * 4;
image_xscale = sign(hsp);

if(Animation_end()){
    sprite_index = spr_knight;
    state = ENEMYSTATE.IDLE;
}
This is for when enemy gets hit. The problem is I don't know how to make them go up first and then fall down and collide with the floor. With this code the enemy just flies through the floor. I could try different codes if you have any ideas.
 
Top