- Home /
Engine weight Simulation
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!
Answer by Waz · Aug 24, 2011 at 12:03 PM
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.
Yeah, the car already has a centre of mass, I don't really want to move it forwards in the car as it negatively effects the handling, it'd be a lot of work to tweak the cars properties again to counter the new centre of mass...
Answer by Rennat · Aug 24, 2011 at 04:54 PM
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
Using ForceMode.VelocityChange : javascript
rigidbody.AddTorque(-rigidbody.angularVelocity, ForceMode.VelocityChange);
Aha!That looks like what I want (applying the inverse of the angular velocity to effectively make it 0) - I'll give that a go and post my feedback here.
Thanks!
hmm, unfortunately, I think there's a problem with my simplistic check of
" if (rigidbody.rotation.x < 40) {"
as it doesn't appear to be triggering.. (not even triggering a debug.log output) - also I notice that if I rotate the car manually around on it's axis the .x will change even if I'm not changing this axis (i.e. if I'm rotating it around .y it moves the .x slightly every now and then)
how would someone limit the angle something could tip to? (imagine a box, I want it to rotate +1 degree until it's at 45 and then stop)
Your answer
Follow this Question
Related Questions
Rotating a Rigidbody with Physics 1 Answer
How may I observe expected physical interactions while using Rigidbody.MoveRotation()? 1 Answer
Freezing Rotation and Joints (Swing / Rope) Physics Issues 1 Answer
drag object including free rotation 0 Answers
How to keep rotation from switching between - and + after a 360? 0 Answers