# Knockback in Platformer

Get help using Construct 2

### » Sun May 26, 2013 12:38 am

So I'm trying to make a system in which when a player or enemy with platform behavior gets hit with a certain attack, they are knocked back and briefly stunned. This kind of mechanic is common in a lot of games, such as fighting games. I have the basics in place - stunning the player and disabling their controls, but getting the actual knockback to work continues to give me trouble.

Knockup in a vertical direction is fairly easy, you just set the Vector Y on the platform behavior and it behaves appropriately. Moving the player in the horizontal direction is more difficult, because the Vector X is affected by the platform behavior's natural deceleration, which is pretty high in my game. I don't want to lower the ground deceleration too much or I'll lose the precise feeling of the controls, but as it is even if I set the vector X to the max speed the platform behavior allows it still barely moves the character backwards at all.

Is there an alternate method to handle knockback better, one that would give me more control? I'd like to be able to do large knockbacks (ie: hit a character across a screen's length), ideally with some control over things like deceleration. It's also important that the knockback continue to interact correctly with solids, such that the character can't be thrown through walls and won't end up with their platform behavior bugged out.

Any thoughts? Have others had to approach this problem? What kind of solutions did you use?
B
7
S
1
Posts: 45
Reputation: 1,315

### » Sun May 26, 2013 3:34 am

Hi,
you can set the max speed and deceleration temporarily,
and then set it back to the previous value after the player regain control
B
8
S
2
Posts: 48
Reputation: 1,098

### » Sun May 26, 2013 3:39 am

If you think of it like the difference between force and impulse in the physics behaviour, instead of applying a vector adjustment once, which would straight away be affected by deceleration, instead, set a variable, and while true , set vector.x to a certain amount.

I did this for wall jumps in a game, I set a variable to 80, then each tick, subtracted 1 from variable, and set vector-x to a fixed number, so the character would move in the air/repel from walls.

Once it hit 0, the vector.x wasn't affected any more.

JohnnySix2013-05-26 03:41:11
B
27
S
9
G
5
Posts: 495
Reputation: 11,964

### » Sun May 26, 2013 6:16 am

[QUOTE=JohnnySix] If you think of it like the difference between force and impulse in the physics behaviour, instead of applying a vector adjustment once, which would straight away be affected by deceleration, instead, set a variable, and while true , set vector.x to a certain amount.

I did this for wall jumps in a game, I set a variable to 80, then each tick, subtracted 1 from variable, and set vector-x to a fixed number, so the character would move in the air/repel from walls.

Once it hit 0, the vector.x wasn't affected any more.

[/QUOTE]

That approach makes a lot of sense, I'll give it a try. Thanks!
B
7
S
1
Posts: 45
Reputation: 1,315