if(vLength(vForce)) GlobalPropulsionForce = vForce;
The magnitude check is not needed. If force is a zero vector, that's fine and would be even ideal.
Another potential problem: Because we compensate the whole error in one step, the missile may be at the right spot in the next frame. But then it's velocity is too high, so we will overshoot in the next frame after that. So we create an oscillation. To prevent this, we need to resolve only part of the error per step, which unfortunately also increases lag, but still worth to try:
dVector vAccel = (vTargetVel - vCurVel).Scale(1.0/dBodyTimeStep * 0.3);
I would test all those things (impulse and force methods) also without the fixed joint, to see if the math is right.
If not, we work against the joint, forces might increase to the point where we get asserts indicating solver explosions.
But the real question to me is: Why does the fixed joint not work, although it did work for you til yet, with other spacecraft?
Is the acceleration of the airplane much higher?
I guess not? So maybe it's something about the joint.
I have similar issues with the ragdoll. If i cause very high accelerations, the bodies separate at the joints. And then the engine tries to resolve the large error with slow constant velocity movement, similar to what happens if we place a body inside another. The large penetration is resolved slowly, and it takes some time even if i stop my joint motors.
Eventually your lag comes from there. The only solution is to avoid very high accelerations. :/
To make the joint more robust, i see two options:
Make sure the attachment point is at the center of mass of the missile, so there is no arm causing angular stress. I assume you have it like that already.
Experiment with the orientation of the joint. Try to align the hinge axis with the length of the missile, but also try to rotate it 90 degrees so the hinge axis is perpendicular. Might make a difference.
The second option is to use the newer accurate / hard joints, instead the older soft joints. This might actually really help.
To do so, you need to create a skeleton containing both the airplane and the missile bodies.
I still have some old code with Julios advice:
- Code: Select all
void EnableStiffJoints (NewtonWorld *world)
{
newtonSkeletonContainer = NewtonSkeletonContainerCreate (world, bodies[HIP], 0);
//NewtonSkeletonSetSolverMode (newtonSkeletonContainer, 1); // should be uncommented i guess
//and add all the children using function
int jointCount = 0;
NewtonJoint *jointArray[NUM_JOINTS];
for (int i=0; i<joints.size(); i++)
{
NewtonSkeletonContainerAttachBone (newtonSkeletonContainer, joints[i]->body0, joints[i]->body1);
NewtonSkeletonContainerAttachBone (newtonSkeletonContainer, joints[i]->body1, joints[i]->body0); // i had those two lines commented out. Maybe only one is needed so we do not add bodies twice
jointArray[jointCount++] = joints[i]->joint;
}
NewtonSkeletonContainerAttachJointArray (newtonSkeletonContainer, jointCount, jointArray);
//and after all the bone are added, the call
NewtonSkeletonContainerFinalize (newtonSkeletonContainer);
//and that's it, now that array of bodies and joint will be result exactly.
}
It's old code and may no longer work, but at least you see some related function calls.
With Newton 4 the skeleton is created automatically for a ndModel and its joints and bodies.
And i need to enable the exact joint solver in the joints constructor:
- Code: Select all
SomeJoint (ndBodyKinematic* body0, ndBodyKinematic* body1)
: ndJointBilateralConstraint(4, body0, body1, dGetIdentityMatrix())
{
//SetSolverModel(m_jointIterativeSoft); // old soft solver
SetSolverModel(m_jointkinematicOpenLoop); // new exact solver
//SetSolverModel(m_jointkinematicCloseLoop);
//SetSolverModel(m_jointkinematicAttachment);
}
I'm not sure if exact joints make a difference for a simple two body, one joint configuration, but i'd have some hope on this. IF you have multiple missiles attached, it should surely help a lot!
If it works, it might be needed to destroy the skeleton once the missile is launched.
But well, hopefully Julio comes back soon...