Object jumps wildly after collision with ground when rotated in flight

Hey there,

I have currently the problem, that I’m launching an Object, which shall rotate in the direction it is flying based on the velocity of the object.
So far, everything works fine, except that, if the object collides with the ground, it stats jumping / rotating like wild.

If I remove the script part, which rotates the object in flight, it bounces of the ground like I want.

here is the code part for the rotation:

if (!isCollided)
            {
                float heading = Mathf.Atan2(rb.velocity.y, rb.velocity.x) * Mathf.Rad2Deg;
                projectile.rotation = Quaternion.Euler(0, 0, heading);
            }

The “isCollided” attribute is set to true on the first occuring collision with the ground and will never change afterwards.

If i comment that out of the code, everything works fine. I think, the rotation messes up the RigidBody2D Material, which creates the bounce effect, but I don’t know, how to solve this :frowning:

Don’t assign directly to .rotation when using physics. This is a “teleport” as far as the physics system goes and you are “alarming” it by jamming a part of your collider into another, so it produces a huge corrective force when it notices the collision.

Instead use the .MoveRotation() on the Rigidbody reference, which gives the physics a chance to resolve the contact properly rather than freaking out.

Same goes for setting the .position directly … don’t do that but instead use .MovePosition() on the rigidbody.

2 Likes