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

GameMaker knockback in platform game

T

TiuZero

Guest
I'm trying to create a knockback system in a platform game, I'm using this

other.hspd = knockBackhspd * sign(other.x-x);
other.vspd = -knockBackvspd

but he only throws the player up, I wanted him to play left and right, I tried to change and add some things, but nothing works, what can I do? can you help me? or if you know of an alternative method please tell me.
 

samspade

Member
We would need to see your code to say for sure, but if I had to guess I would say that you have something like the following in your player's step event:

Code:
hspd = (right - left) * spd;
Or really just something which says hspd = something else. As soon as you set hspd like that you are wiping any prior information it might have had, resetting hspd each step.

There are two basic solutions. The first would be to switch over to a acceleration system (which is what is most people use for vspd). The second is to add knockback to its own variable which you manage separately form hspd and add to hspd each step.

Code:
hspd = (right - left) * spd;
hspd += knockback;
 
T

TiuZero

Guest
We would need to see your code to say for sure, but if I had to guess I would say that you have something like the following in your player's step event:

Code:
hspd = (right - left) * spd;
Or really just something which says hspd = something else. As soon as you set hspd like that you are wiping any prior information it might have had, resetting hspd each step.

There are two basic solutions. The first would be to switch over to a acceleration system (which is what is most people use for vspd). The second is to add knockback to its own variable which you manage separately form hspd and add to hspd each step.

Code:
hspd = (right - left) * spd;
hspd += knockback;
man, you got it right my step event, how would i do the knockback? in
what events do i have to post? and in what? player or enemy?
I'm sorry, I'm a layman
 
Top