What I would like is a function that gets called every frame and adjusts the course. Right now I have the following (java code from libgdx using a bullet wrapper):
Code: Select all
ENG_Vector4D entityPos = entityProperties.getNode().getPosition();
ENG_Quaternion entityOrientation = entityProperties.getNode().getOrientation();
ENG_Vector4D othEntityPosition = otherEntityProperties.getNode().getPosition();
ENG_Quaternion othEntityOrientation = otherEntityProperties.getNode().getOrientation();
ENG_Vector4D diff = otherEntityProperties.getNode().getPosition().subAsVec(entityProperties.getNode().getPosition());
diff.normalize();
ENG_Quaternion rotationTo = entityProperties.getNode().getLocalInverseZAxis().getRotationTo(diff);
btTransformUtil.calculateVelocityQuaternion(new Vector3(entityPos.x, entityPos.y, entityPos.z),
new Vector3(othEntityPosition.x, othEntityPosition.y, othEntityPosition.z),
new Quaternion(entityOrientation.x, entityOrientation.y, entityOrientation.z, entityOrientation.w),
new Quaternion(rotationTo.x, rotationTo.y, rotationTo.z, rotationTo.w),
MainApp.getMainThread().getCurrentElapsedTime(), linearVelocity, angularVelocity);
entityProperties.getRigidBody().applyTorqueImpulse(angularVelocity * some scaling); //This makes no sense, I know
Any idea on how I can gently slow down correctly when the missile is almost on target?
Another constraint that I forgot about is that the missile has a maximum angular velocity, so the impulse must not make the missile rotate more distance per second than allowed. If that limit is reached then the missile should simply fly around the target, missing it.
[EDIT]: The game takes place in space and there is no gravity. But there is angular and linear damping so things don't spin and move endlessly. I also checked the first answer from https://answers.unity.com/questions/488 ... sort=votes but I am not able to find the equivalent values from PhysX in Bullet. Namely the inertiaTensorRotation and the inertiaTensor. It seems bullet only uses inverse values for these things.