# Rigidbody Rotation Problem

I have a rigidbody with wheelcolliders and I am using a spline (Super Splines) to guide the rigidbody round a track. It’s not been without problems, fighting with the physics but, I have a solution I am happy with a seems stable.
The last issue I am having is with rotation of the rigidbody whilst in the air to do a flip. It can rotate forward or backwards up to 90 degrees and then just flips out. I am controlling the Y axis via a point on the spline, trying to lock the Z axis down to stop any tipping from side to side and then I want to leave the X axis to the physics.

Here are the methods that make this happen,

``````void HandcarRotation()
{
float rotationX = myTransform.rotation.eulerAngles.x;
float rotationY = splineRotation.eulerAngles.y;
float rotationZ = myTransform.rotation.eulerAngles.z;

myTransform.rotation = Quaternion.Euler(rotationX, rotationY, rotationZ);
}

void SetToSplinePosition()
{
//set the local x velocity to zero to help prevent sliding off the spline
Vector3 localVelocity = myTransform.InverseTransformDirection(myRigidbody.velocity);
localVelocity = new Vector3(0f, localVelocity.y, localVelocity.z);
myRigidbody.velocity = myTransform.TransformDirection(localVelocity);

//set handcar position onto spline
Vector3 position = new Vector3(splinePosition.x, myTransform.position.y, splinePosition.z);
myTransform.position = position;
}

void LockZRotation()
{
//freeze localz rotation
Vector3 localRotation = myTransform.localRotation.eulerAngles;
localRotation = new Vector3(localRotation.x, localRotation.y, 0f);
myTransform.localRotation = Quaternion.Euler(localRotation);
}

void TiltControl()
{
if(!IsGrounded())
{
float tiltDirection;
tiltDirection = Input.acceleration.y;

myRigidbody.AddRelativeTorque(Vector3.left * tiltDirection * tiltForce, ForceMode.Acceleration);
}
}
``````

If I had to guess I would say it’s something to do with local and world coordinates but, I’m not sure how to fix it.