Greetings Unity Community.
I am currently working on a small project to create a MotoCross style dirt bike simulator/game. So far I have gotten an object hierarchy like such:
Bike
Body
Wheels
Front
Rear
Wheel Collider
FrontCol
RearCol
I am actually rather happy that I have also been able to use a simple script to produce forward velocity using RearCol.motorTorque * Input.GetAxis(“Vertical”). Add a bit of drag and I have a basic motorcycle that can accelerate forward and slow to an eventual stop when I release the throttle.
Now comes the part I haven’t found an answer for. TURNING. I have experimented with the following items and got the following results:
Tried using the FrontCol.steerAngle * Input.GetAxis(“Horizontal”). This was nice but the bike flips over after just a small amount of turn.
Tried using rigidbody.MoveRotation around the Z axis (forward) and get the same result.
So from my research I have gathered the following inferences:
- Once the body tilts, it will continue to tilt until it falls unless countered by some force.
- The real world force that causes a bike to stay upright is angular momentum.
So here is my questions:
Is there such a thing as angular momentum in Unity that I am overlooking? If so, where do I access it?
If there is not angular momentum, how would I simulate this correctly in my script to always ‘pull’ the bike back to the straigh upright position over time when the left and right buttons are released?
Thank you greatly in advance for any insight you may provide in this matter.