# Rigidbody rotation constantly spins upon collision.

Hey! I’ve recently started learning Unity and am just now learning about physics and how to code with them in mind.

[Context]
I have created a sphere that moves with Add Force. The X and Z axis are frozen but I have the Y axis unfrozen for gameplay purposes. Interpolation is turned to interpolate. The camera rotates around the sphere in third person and the force is added to the sphere using both key inputs and the cameras position relative to the sphere. Ther sphere is on a terrain that has hills. The mass is 1.85 but can be changed if need be.

The problem I am facing is that whenever the sphere collides with the terrains hills, the sphere starts to rapidly spin out of control, which makes the camera jitter. I have read online that affecting the ridigbody’s mass would lessen the spin or completely fix the issue; however, that has not solved the rapid spin. Here is my code.

``````using UnityEngine;

public class cameraController : MonoBehaviour
{

public GameObject Player;
public Transform cam, player;
public float mouseSens;
public float speed;
private float mouseY, mouseX;
private Rigidbody rb;
private Vector3 rotationVector;

void Start()
{
rb = Player.GetComponent<Rigidbody>();
Cursor.lockState = CursorLockMode.Locked;
Vector3 rotationVector = new Vector3(0, mouseX, 0);
//offset = (cam.transform.position - target.position).normalized * camDistance;
}

void FixedUpdate()
{
Rotate();
}

public void Rotate()
{

mouseX += Input.GetAxis("Mouse X") * speed;
mouseY += Input.GetAxis("Mouse Y") * speed;
mouseY = Mathf.Clamp(mouseY, -35, 89);

transform.LookAt(cam);

cam.rotation = Quaternion.Euler(mouseX, mouseY, 0);
Quaternion deltaRotation = Quaternion.Euler(rotationVector * Time.deltaTime);
rb.MoveRotation(rb.rotation * deltaRotation);

}
}
``````

Help and insight would be greatly appreciated by this newbie!

Try to set Rigidbody angular drag to some higher value if this is acceptable.

Update for anyone with a similar problem: Freezing the Y Rotation of the object can fix this problem. Unfortunately, I need the Y Rotation for my game. I am currently investigating ways I could create a rotation while still freezing the Y rotation on my Rigidbody. Once again, open to input and advice.

this happened to me with Rigidbody2D,
The issue turned out to be my object was rotated 180 degrees around the y-axis
but I guess since the physics 2D system knows nothing about rotation around y-axis, that caused weird behavior.

• if you’re having this in 3D rigidbody, then maybe check the scale of your object, check if it’s negative

I ran into a similar problem with Rigid2D Body.
In my case, I saw I had value for inertia which caused the problem so I turned on the “Freeze Rotation” flag and it solved it