How to make character recoil but make the character bounce high first...

xboxown

Member
Hello,

I have one question to ask. I want when the character hits any enemy or trap to make the character recoil back, but not just recoil on the same level. I want the character to bounce back more likely than just recoil on the same height as the enemy and the player. If I moving right and got hit on the right side, I want the character to bounce at a certain height back to left and if hit by left to bounce back to the right. Anyone can help me on this will be greatly appreciate it.

Thanks in advance.
 

Rexzqy

Member
im a bit confused if u want to do gun recoil or getting knocked back by enemy, but u could check the direction the enemy that hits u is at by using point_direction, and if the enemy's at right side then get knock back toward left.
 

xboxown

Member
Ok so point_direction. Is there a code or an example that shows how that works? This is the first time I am doing this, so any help would be greatly appreciate it. Thanks. :)
 

Rexzqy

Member
Ok so point_direction. Is there a code or an example that shows how that works? This is the first time I am doing this, so any help would be greatly appreciate it. Thanks. :)
basically first u need to know which enemy hits u. to do that, u can probably add a variable in ur player, let's say, "it_just_hit_me". when the enemy hits ur player, set obj_player.it_just_hit_me = id(this is the instance ID of that enemy). then u can do something like if it_just_hit_me != noone (something just hit u), then check for point_direction(x,y,it_just_hit_me.x,it_just_hit_me.y), if thats on the right side(check for angles) then get knocked back to left and if left then knocked to right.

Probably needs modification, but idk, its what came up on top of my head.
 

Rexzqy

Member
Ok so point_direction. Is there a code or an example that shows how that works? This is the first time I am doing this, so any help would be greatly appreciate it. Thanks. :)
im not entirely familiar with how platformers work, but i think to get knocked upward just means u have to add vsp..? and then let the gravity system to let him fall gradually
 
Top