Motorcycle/Bike Physics Trouble

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:

  1. Once the body tilts, it will continue to tilt until it falls unless countered by some force.
  2. 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.

Im no expert and im not sure of the exact code you would use but i would

set normal position then

whenever left or right key is not pressed return to normal position over time

good luck

I am facing little different issue with bike racing game… my bike flips after a level of speed but tuning of rotating bike is fine…
you can check this link
http://forum.unity3d.com/threads/146724-Motorcycle-Physic-Move-bikes-up-from-back-side

If you need a counter balance to your bike, you can AddTorque to the Rigidbody based upon angular velocity - this will allow you to push the bike back to a stable position you deem “stable”.

maybe u could make two front wheels just a little far apart so just to stablieze it and u could also define a center of mass in the -y direction if it still flips u can use a downforce
Hope I Helped!!! :smiley:

lower the center of mass helps

Rigidbody.centerofmass.y = lower than before

you could use a transform for the center of mass.

var com : Transform;
function Start(){
RigidBody.Centerofmass = com.transform.position
}