Force application problem

Starfox
Posts: 37
Joined: Wed Jul 27, 2011 12:01 am

Force application problem

Post by Starfox »

I'm trying to get a two-engine-brick (hopefully a VTOL in the future) to fly using Bullet, and so far I'm applying force at its edges based on the input of L2 / R2 on a gamepad. I think I'm doing something wrong with the force vector transformation because after a 180 degree rotation the force vector doesn't feel right. Here's a video to explain what I mean, the thing should be doing a barrel roll here but it starts reversing once it turns over:

http://youtu.be/8R92hvQLALA

Here's the code I'm using to apply the forces:

(LeftStick and RightStick control the engine rotation around the X axis, LeftAnalog and RightAnalog control the engine strength)

Code: Select all

btTransform Transform;
    VTOL->rigid_body->getMotionState()->getWorldTransform(Transform);
    btMatrix3x3 Basis = Transform.getBasis();
    btQuaternion LeftQuaternion(btVector3(1, 0, 0), LeftStick * deg_to_rad(EngineMaxAngle));
    btQuaternion RightQuaternion(btVector3(1, 0, 0), RightStick * deg_to_rad(EngineMaxAngle));
    btVector3 LeftForceVector = btVector3(0, LeftAnalogValue * EngineMaxForce, 0);
    btVector3 RightForceVector = btVector3(0, RightAnalogValue * EngineMaxForce, 0);
    LeftForceVector = btMatrix3x3(LeftQuaternion) * LeftForceVector;
    RightForceVector = btMatrix3x3(RightQuaternion) * RightForceVector;
    LeftForceVector = Basis * LeftForceVector;
    RightForceVector = Basis * RightForceVector;
    float Offset = .4f;
    VTOL->rigid_body->applyForce(LeftForceVector, btVector3(-Offset, 0, 0));
    VTOL->rigid_body->applyForce(RightForceVector, btVector3(Offset, 0, 0));
    VTOL->rigid_body->setActivationState(1);

What am I doing wrong here?