- Home /
increasing knockback of a rigidbody as received damage increases (like super smash)
I am developing a 2D game, I need to increase force applied by effectors (knockback) according to damage received by the objects (similar to super smash bros. series). For example:
I apply a force with a magnitude of 100:
object#1 received 0 damage, applied force = 100 (the same)
object#2 received 40 damage, applied force = 160 (increased)
object#3 received 90 damage, applied force = 230 (increased even more)
an image the clarifies the idea (from smash bros):
the ideas I came up with:
1- decrease the rigidbody's mass as the received damage increases. The problem of this idea is that normal collisions will be affected as well, I need effectors only to have more knockback.
2- call addForce() manually, great flexibility, but needs more calculations and work to be done.
I am very intersted in the way super smash is developed. If someone has an idea to achieve similar behavior, then please let me know.
Thanks.
Answer by MelvMay · Mar 13, 2017 at 08:17 AM
Why does transforming damage using Rigidbody2D.AddForce mean more calculations?
I would've thought trying to configure an effector to do this, more complex. If you want one-on-one forces, doing it "manually" is far better. A simply "damage" script should be easy to set-up. You can call it via some collision callback and it can determine damage taken, knockback forces to apply etc. I would've thought that would give you much more fine-grained control.
Yeah, I certainly wouldn't start adjusting things like mass to increase the effective force to make things easier; it'd make things harder.