J
Jacco
Guest
Hi all,
I have a problem with creating knockback. I want a player to have a little bit of horizontal and vertical speed when hit by a bullet. So when colliding with a bullet, the variables hsp and vsp of the player should change. However only vsp changes!
Heres my code i have in the step event of the bullet:
and here is the code I use in the player object:
My guess is the bullet gets destroyed before the hsp is increased or maybe because the hsp is set back to move * walksp faster than the collision happened. I tryed putting the first code in a beginstep event or endstep event, but it didn't work. When i don't destroy the bullet the code works and the hsp increases. But I want the bullet to get destroyed. Do you guys have any idea what is going wrong, and what is a solution? I'm using GameMaker 2 btw.
Thanks!
I have a problem with creating knockback. I want a player to have a little bit of horizontal and vertical speed when hit by a bullet. So when colliding with a bullet, the variables hsp and vsp of the player should change. However only vsp changes!
Heres my code i have in the step event of the bullet:
Code:
if (place_meeting(x,y,obj_player1))
{
with(obj_player1)
{ hp--; //hp -1
flash = 3;
hitfrom = other.direction;
direction = hitfrom;
hsp += 3;
vsp += -3;
}
instance_destroy();
}
Code:
if(!place_meeting(x,y,obj_bullet))
{
hsp = move * walksp;
}
vsp = vsp + grv;
Thanks!