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.
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.
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;
}