- Home /
Knockback and Launch Angle
I'm trying to find a decent code for knockback and launch angles. I keep on finding code snippets that were like...
rigidbody.velocity.x = 4f;
rigidbody.velocity.y = 2.5f;
but that is not what I was looking for.
I was looking for something that involves sin() and cos(), then multiply by knockback. That way, I can only enter an angle and knockback force in the inspector.
Oh, and this will be 3D space. So I want angle 0 to be the hitbox's local forward, angle 90 to be up, and 180 to be backwards.
Comment
Best Answer
Answer by hav_ngs_ru · Dec 25, 2014 at 03:27 PM
rigidbody.velocity = Quaternion.AngleAxis(-yourAngleHere, transform.right) * transform.forward * yourKnockBackForceHere;
Then declare public yourAngleHere and yourKnockBackForceHere and set it in inspector;