I have a btRigidBody which moves in a manner similar to a helicopter - lift counters gravity, tilt provides lateral motion at the expense of lift.
This works fine at first, however when I Yaw (almost like using a tail rotor) while moving (I know you dont do this in a real helicopter!) some roll is introduced.
This looks great but makes it hard to control. I want to add a stabilising check to bring the craft back to level if rolling. At present, my craft is flipping onto its back! Can anyone see my probably obvious mistake?
Code: Select all
btTransform tr = m_body->getWorldTransform();
// is tdoty correct?
// ROLL_CORRECTION constant lets me adjust sensitivity
btScalar rollAmount = tr.getBasis().tdoty(btVector3(0.0f, 1.0f, 0.0f)) * ROLL_CORRECTION;
// craft points down X-axis, so this produces the roll
btVector3 vr( rollAmount, 0.0f, 0.0f);
m_body->applyTorqueImpulse( tr.getBasis() * vr );
Thanks
Simon
EDIT:
How about this:
Code: Select all
btTransform tr = m_body->getWorldTransform();
btScalar y, p, r;
tr.getBasis().getEulerYPR(y,p,r);
// ROLL_CORRECTION is negative
btVector3 vr( r * ROLL_CORRECTION, 0.0f, 0.0f);
m_body->applyTorqueImpulse( tr.getBasis() * vr );