Getting and setting angular velocity in body space?
Posted: Sat Mar 18, 2023 5:37 pm
I'm trying to create a motorcycle, the standard gyroscopic effect doesn't seem to be enough to keep it from tipping over.
I've been trying to find a way to basically apply a rotation around the long axis of the bike inversely proportionate to how far tilted the bike is on that axis.
I thought this would be really simple, but pretty much everything I try causes the bike to glitch out horribly eventually.
My original plan went something like this:
When this didn't work, I tried something really simple:
And I noticed that actually did work... so long as the car was generally facing a straight direction. As soon as you turned it, it would glitch out. Which I assume is because it's getting angular velocity according to the world's Z axis, not the car's Z axis.
How can I get and set angular velocity according to the body's orientation, or more generally correct an object tipping over on one axis?
I've been trying to find a way to basically apply a rotation around the long axis of the bike inversely proportionate to how far tilted the bike is on that axis.
I thought this would be really simple, but pretty much everything I try causes the bike to glitch out horribly eventually.
My original plan went something like this:
Code: Select all
btQuaternion quat = carBody->getWorldTransform().getRotation();
float angX,angY,angZ;
quat.getEulerZYX(&angZ,&angY,&angX);
btVector3 angVel = carBody->getAngularVelocity();
angVel.setZ(angVel.getZ() + -angZ);
carBody->setAngularVelocity(angVel * someScalingFactor);
Code: Select all
btVector3 angVel = carBody->getAngularVelocity();
angVel.setZ(-angVel.getZ());
carBody->setAngularVelocity(angVel);
How can I get and set angular velocity according to the body's orientation, or more generally correct an object tipping over on one axis?