- Home /
How to manage Physics2D bounciness so an object does not rotate like crazy after the bounce?
Hello, I've encountered a problem while trying to make my objects bounce off each other.
When one of my objects of mass 1 hits the brown object of mass 500 the brown objects starts rotating very fast in the highlighted direction. I have tried increasing angularDrag but it only manages the drag it self instead of Angular Force or something similar.
The question is: Does Unity have a more sophisticated bounce component? Or the only way would be writing a script?
Thanks in advance :)
Student of University of Essex,
Laurynas Pupsta
Answer by Arcade-Perfect · Feb 10, 2016 at 05:41 PM
there small option in the rigidbody2D component called: Freeze Z Rotation. mark it and wa-la!
also you can make a simple script that freeze the rotation by writing in the FixedUpdate $$anonymous$$ethod:
transform.rotation = Quaternion.identity;
Answer by LaurynasP · Feb 14, 2016 at 05:56 PM
Well, TBH I just wrote a script to emulate the hit with forces at the collided point. Then I tweaked the force of the hit to the shape and done. Thanks for the answers tho! Cheers The code that solved my problem:
void OnCollisionEnter2D(Collision2D collision) {
if (collision.gameObject.name == "shape")
{
Rigidbody2D hitRb = collision.gameObject.GetComponent<Rigidbody2D>();
hitRb.AddForceAtPosition(rb.mass*rb.velocity, collision.contacts[0].point);
GameObject.Destroy(gameObject);
}
}
Your answer
Follow this Question
Related Questions
Bouncing problem 0 Answers
Inconsistent physics with knockback and bouncing. 0 Answers
Odd behavior when circle collider is supposed to bounce off wall 1 Answer
How to change bouncing direction 2 Answers
Changing 2d Destination by angle 1 Answer