Compensating for Roll of btRigidBody

sipickles
Posts: 44
Joined: Thu Aug 07, 2008 6:57 am

Compensating for Roll of btRigidBody

Post by sipickles »

Hello,

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 );
Perhaps there is a better way to do this anyway :)

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 );
Feels more stable, then suddenly flips! I need a way to do this in object local space I think
Zenja
Posts: 14
Joined: Fri Jul 10, 2009 4:48 am

Re: Compensating for Roll of btRigidBody

Post by Zenja »

I have a similar problem (applying torque to change roll also changes the pitch in subsequent calls) which introduces instability in my object controller. I believe that I've identified the problem - the torque I'm calculating is object relative, while when calling btRigidBody::applyTorqueImpulse() the torque is multiplied by the world transform, which is not what I need. Now to figure out how to compensate ...

Edit Zenja: It does help to read the forum post your responding too, since it sometimes includes the answer you seek :)

Code: Select all

btTransform bt;
body->getMotionState()->getWorldTransform(bt);
body->applyTorqueImpulse( bt.getBasis()*torque * mass);
Current mood: Ecstatic.