After collison random permanent rotation imparted

I have a problem with this part of the course as well as the previous obstacle course. Everything works just like in the course until the physics simulation actually hits something, like the ground. After that, a permanent rotation force seems to remain active (happened in both courses). Without any keypress of course. Hitting another object might reset the rotation or impart another rotation.

I am using 2022.1.13f. What am I missing?

1 Like

Hi Jaapjan!

I have the same problem. Adding some angularDrag helps a bit, but doesn’t solve the problem completely.

Best regards,
rdom

On the Rigidbody you can freeze certain rotations to prevent this from happening

I do understand that. In the case of my Obstacle Course example however I did not do any direct manupulation of the transform which causes the need for freezing.

In the Obstacle Course example I used an animation controller with a character. This animation causes movement direct on the transform instead of physics?

It doesn’t matter how you handle movement. If there’s a non-kinematic Rigidbody on the component, physics will change its rotation when it collides with something. If you are not using physics for movement or gravity, change the Rigidbody to kinematic.

What eventually worked for me after a lot of searching on the unity stack overflow: Increasing angular drag on the rigid body helped a lot. (Going to 10000) or so.

1 Like

I added the below workaround script on the landing pads, so the player could have a safe landing without the rocket toppling over after game over. Note that in my world X-axis points towards the camera, Y up and Z to the right. You could add the same on ground, but IMO the rocket falling if it lands on “uneven” ground instead of the landing pad is more a feature than a bug :wink:

using UnityEngine;

/**
 * A hack to stop rocket from rotation when it's landed. Prevents it from keeling over on its own after the game is over.
 */
public class SafefLanding : MonoBehaviour
{
    private string playerTag = "Player";
    private Rigidbody playerBody;

    // Start is called before the first frame update
    void Start()
    {
        var player = GameObject.FindGameObjectWithTag(playerTag);
        if (player != null)
        {
            playerBody = player.GetComponent<Rigidbody>();
        }
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    private void OnCollisionEnter(Collision collision)
    {
        if (collision.collider.CompareTag(playerTag) && playerBody != null)
        {
            // TO DO: disable only if player got the rocket "straight enough"
            playerBody.useGravity = false;
            playerBody.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ;
        }
    }

    private void OnCollisionExit(Collision collision)
    {
        if (collision.collider.CompareTag(playerTag) && playerBody != null)
        {
            playerBody.useGravity = true;
            playerBody.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
        }
    }
}

Privacy & Terms