Add Recoil/Knockback to a player sprite

Just started using Construct 2? Post your questions here

Post » Mon Sep 15, 2014 5:12 pm

Hello all, first post here.

I'm attempting to make a 2D action platformer, the player sprite has a weapon sprite (a gun) attached to them which aims and fires towards the mouse cursor.

I would like firing the gun to apply a large knockback to the player, in the opposite direction to which way the gun is facing. Physics behaviour seems the most straightforward way of doing this.

I'm aware that attempting to mix platform behaviour and physics behaviour on a sprite is regarded as a bad idea so I've got the player as a having physics behaviour but not platform, movement is done with forces and impulses, is this also a bad idea? An issue I'm finding with this is that having 'Jump' as an upward impulse causes the player to lose all sideways momentum.

Having firing the gun apply an impulse away from the mouse cursor doesn't seem to be working. Could this be because the weapon sprite is pinned to the player sprite? Would it be better to just set the weapon sprite X, Y to the player sprite X, Y every tick?

My project is very rudimentary at the moment and I'm still working on a lot of the fundamentals so I don't think there is much benefit to sharing the .capx at this point.

As you can guess, I'm a noob at this so any help is greatly appreciated, even just general tips and pointers. Thanks!
B
2
Posts: 1
Reputation: 152

Post » Mon Sep 15, 2014 6:30 pm

You can use the Platform behaviour and set the X vector to the opposite direction of the gun.
B
84
S
20
G
6
Posts: 175
Reputation: 8,156

Post » Mon Sep 15, 2014 6:35 pm

@Robin Sommer is correct. Add the behavior "Physics" and apply an initial 1 time force each time he fires and you will get the effect your looking for.
[b]Andrew Donelson[b]
Nlaak Studios, LLC
https://www.nlaak.com/
[email protected]
B
15
S
3
Posts: 66
Reputation: 1,136


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 2 guests