Problems with applying forces

Problems with applying forces


I'm just starting with Havok so apologies if this is a dumb question, I'm sure I'm overlooking something simple or doing things the wrong way but I've tried everyting I can think of and am still having the same issues.

Anyway, I'm trying to make a 3rd person flight game where the spaceships are flying over a planet surface and are subject to gravity using Havok linking to Ogre for the graphics rendering. I have all this set up so the Ogre mesh produces a rigidBody in Havok and the ship falls under gravity and can be pitched, yawed and moved forward under thrust. The issue I'm having is that there seems to be a limiter on the speed the ship will travel, it accelerates to a certain speed to start with and then no matter how much I increase the thrust it doesn't seem to go any faster. The code I'm using is below:

void PlayerShip::update(Real elapsedTime, OIS::Keyboard *input) {
    //apply thrust
    bearing = hkVector4(0, 0, 1);
    hkTransform trans = mBody->getTransform();
    hkRotation currRot = trans.getRotation();
    bearing.setRotatedDir(currRot, bearing);

    if (input->isKeyDown(OIS::KC_P)) {
          if (thrust < 2500)
          thrust += 5;
    if (input->isKeyDown(OIS::KC_L)) {
          if (thrust > 5)
          thrust -= 5;

    if (input->isKeyDown (OIS::KC_W)) {
              hkVector4 rot = hkVector4(1, 0, 0);
              hkTransform trans = mBody->getTransform();
              hkRotation currRot = trans.getRotation();
              rot.setRotatedDir(currRot, rot);
              mBody->applyTorque(elapsedTime, rot);

// All other keys, S, A, D, perform a rotation as above but in a different direction

As you can see I'm having to multiply my applyTorque values by huge amounts to get any real rotation so I wonder whether this is anything to do with my problem? Also, the models I am using to produce my Rigid Bodyare scaled up to be around 8 times the size of a real life object (They are from the Ogre tutorial and are the best I have at the moment) soI didn't know if this could also be an issue, although I have given my ship a very low mass of 1000 / 8 (as its 8 times the size of what it should be using SI units).

Hopefully I've given enough information for someone to have a crack at what my issue might be but if not please let me know and I can happily post more detail.


5 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

Hey Denver,

Could you tell me more about the hkpWorldCInfo and hkpRigidBodyCInfo you are using in order to construct your physics world and spaceship respectively? I would particularly be interested in looking at the Inertia Tensor values you are initializing your rigid body with.

Also it seems, that you have two issues right? One being that you can't accelerate the Spaceship after a certain threshold, the other being that you need to multiply your Torque by huge amounts in order to get any visible rotation.

Can you also let me know the linear velocity of your Spaceship when you cannot increase it anymore? And, if you are updating your spaceship's physics in any other location of your game, what you are applying to it there?

Thanks for letting me know,

David G. Developer Support Engineer Havok

Hi David, thanks for your reply. I have resolved the first issue about the acceleration after a certain threshold, turns out all I needed to do was apply setMaxLinearVelocity to the rigidbody, so it was something simple after all! Regarding the rotation, I still have issues. I can reduce the amount I have to multiply my torque by if I increase the stepTime from elapsedTime (which is the time since the last frame) to, say, 5.0f but I'm not sure this what I should be doing. The info you ask for about constructing the physics world is below.

mShape = HkOgre::Cooker::processOgreMesh(getEntity());
hkpRigidBodyCinfo chassisInfo;
chassisInfo.m_shape = mShape;
chassisInfo.m_motionType = hkpMotion::MOTION_DYNAMIC;
chassisInfo.m_angularDamping = 0.1f;
chassisInfo.m_mass = mass;
chassisInfo.m_friction = 0.1f;
mBody = new hkpRigidBody(chassisInfo);
mBody->setMaxLinearVelocity(1500); //this is the new line that resolves my velocity issue!

hkpWorldCinfo worldInfo;
worldInfo.m_collisionTolerance = 0.1f;
worldInfo.m_gravity.set(0.0f, -9.8f, 0.0f);
worldInfo.m_contactPointGeneration = hkpWorldCinfo::CONTACT_POINT_ACCEPT_ALWAYS;
worldInfo.m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_MULTITHREADED;
worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_FIX_ENTITY;

physicsWorld = new hkpWorld(worldInfo);

Hopefully that makes sense, I can probably work around it if not as the main problem was the one I have resolved, but if you can advise of a better way I should be working, or at least confirm I'm not doing anything really wrong then it would be much appreciated.



Hey Denver,

Does the Ogre Tutorial, where you took your SpaceShip Asset from, also use Havok? It would be great if you could give me the values of the spaceship's hkpRigidBody's masses and m_motion's m_inertiaAndMassInv in both the Tutorial and your application. Also, because the models you are using to produce your Rigid Body is scaled up to be around 8 times the size of the real life object, you should probably multiply the real life mass of your object by 8 (If the real life's object Mass is 1000 then your object's mass should be 1000 * 8 instead of 1000 / 8 and you should apply 8 times the torque that is applied to the real life's object in order to produce the same angular velocity.).

In fact, the mass set for your object will influence its hkpRigidBody's m_motion's m_inertiaAndMassInv (ie.: The bigger it is, the bigger the torque magnitude applied to the object should be to produce the same angular velocity) and you should then not need to hack in the stepTime from elapsedTime.

Let me know how it goes,

David G. Developer Support Engineer Havok

Hi David,

Thanks for your advice, I've actually decided to move the ship around with setTransform instead of using forces, as realistic physics isn't crucial to my game and my tutor (the game is for my final uni project) advised me to try doing this this way as it may be quicker.

Thanks for your help though, it was much appreciated. I may well be back with other problems as I encounter them so its good to know there are people to help! I'm currently struggling with my ContactListener implementation throwing up hundreds of errors in hkContactPoint (which I've not amended or done anything to!) and a couple of other classes, but I'm sure I'm just doing something wrong and will get it sorted out, if not, watch this space... ;o)



Connectez-vous pour laisser un commentaire.