Hello, I’ve been running at this for a while now and cannot find the right solution to this issue. (I’m pretty terrible at maths like this!)
basically, I want my car to simulate the weight of an engine whilst in flight (i.e. going over a jump), I want the car to “nose down” to an angle of 40 degrees on the x maximum.
I’ve used rigidbody.addrelativetorque(100,0,0) and that continues to nose over too much. Then I tried to say “okay, once you’re < 40 degrees set the angularvelocity to 0)”
this doesn’t appear to work.:
if (airborne) {
if (rigidbody.rotation.x < 40) {
rigidbody.AddRelativeTorque (nosedip);
} else { rigidbody.angularVelocity = Vector3.zero;}
}
“nose dip” is simply a vector3 = (100,0,0)
I’m pretty sure there’s a better way to do this, and I’ve looked into lerps and slerps, and quaternions and such but it’s all out of my league!
Sounds like you’re trying to fake something. You can set the Center Of Mass of a Rigidbody. You may also need to tweak Angular Drag to get what you’re after.
Sometimes changing the center of mass depending on whether you’re on the ground or not can help with realism.
To continue with the way you’re doing it now instead of setting the angular velocity to zero you can add force as an impulse or velocity change with the ForceMode parameter.
Using ForceMode.Impulse : javascript:
// this is the amount of force it would take to stop the current rotation
var oppositeTorque : Vector3 = -rigidbody.angularVelocity * rigidbody.mass;
rigidbody.AddTorque(oppositeTorque, ForceMode.Impulse);
I haven’t used it but there is also a ForceMode.VelocityChange which I would imagine would work like this