I’m having issues thinking of a good way to align my bike to the surface its riding on by modify the local z axis, without messing up the rigidbody simulation. I am able to get my bike to balance by modifying the transforms local euler angles as such:
var euler = transform.localEulerAngles;
// Only works for staying upright relative to ground plane
transform.localEulerAngles = new Vector3(euler.x, euler.y, -steerLean);
The issue here is that when I go up a vert ramp the bike aligns, obviously, straight upwards. I cannot think of / recall a good way to keep the object upright but keep the rigidbody simulation intact otherwise.
I have tried to use Quaternion.FromtoRotation but this does not seem to want to play nicely. The object flops from left to right and eventually just falls over.
My bike uses WheelColliders and is working fine other than this issue.
Picture above for reference. The bike is moving and should be leaning to the right.