Lag in joints attached to a kinematic

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
NetSavant
Posts: 28
Joined: Wed Apr 20, 2011 10:50 pm

Lag in joints attached to a kinematic

Post by NetSavant »

Hey, had a quick question - I've got a ragdoll model that gets launched from a launch platform - while on the platform I'm adjusting the central body Box entity kinematically by setting its WorldTransform property, and letting the attached dynamic limbs dangle and adjust accordingly.

Post-launch, when the body is dynamic, all the constraints work beautifully and limbs stay attached - but while on the platform moving around, there's about 15 frames of lag where the limbs slowly catch up to the moving body (their velocity dies away the closer they get to the correct positions).

Not a big deal as the limbs are just used as orientations for bones in an avatar model, so the lag isn't real noticable in-game, but curious what's happening there - is it because velocity information is lost in the body when setting position / orientation directly, and so the solver is missing what it needs for the joints to work out right? Should I manually recreate the velocities after a change in position, or maybe manipulate the body indirectly by adjusting the velocities instead of the WorldTransform?

Thanks -

-Luke
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Lag in joints attached to a kinematic

Post by Norbo »

is it because velocity information is lost in the body when setting position / orientation directly, and so the solver is missing what it needs for the joints to work out right? Should I manually recreate the velocities after a change in position, or maybe manipulate the body indirectly by adjusting the velocities instead of the WorldTransform?
That's basically all correct, yup. Setting the position/orientation/world transform is teleportation, as opposed to physical movement.

The solver is velocity-based. If there's no relative velocity to correct, then only the position error correction gets fed into the velocity solver and it behaves a bit like a spring (a pretty damped one, by default).

If the velocity matches the motion, the solver will be able to make it look right. The 'most correct' option would be to use velocities to drive the motion completely, without fiddling with the position directly. Of course, if it's a discontinuous jump over a long distance, the velocity involved would be quite gigantic and result in significant flailing, so it might be better just to choose to teleport every part of the body in such a case.
NetSavant
Posts: 28
Joined: Wed Apr 20, 2011 10:50 pm

Re: Lag in joints attached to a kinematic

Post by NetSavant »

Thanks Norbo - updating the body by velocity worked good.

There is a case where the ragdoll gets "reloaded" onto the launch platform, and I'm having some trouble with the limbs destroying everything in their path on the way back - working on some code to teleport all the body parts individually, will see if that takes care of it.
NetSavant
Posts: 28
Joined: Wed Apr 20, 2011 10:50 pm

Re: Lag in joints attached to a kinematic

Post by NetSavant »

Hmm, getting strange behavior with limb-teleportation - I'm basically making the body entity kinematic, teleporting it to the launcher, then updating the limb WorldTransforms so that they're in the same configuration as before but relative to the body's new position. What seems to happen is the limbs get scattered all around the new body position in about the radius of the teleportation distance, and then gradually snap back into order.

Don't want to bug you with my code details too much - but offhand, is there anything I need to do to "reset" the joint constraints in that scenario, or anything special when it comes to teleporting dynamic entities?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Lag in joints attached to a kinematic

Post by Norbo »

is there anything I need to do to "reset" the joint constraints in that scenario, or anything special when it comes to teleporting dynamic entities?
Not that I can think of off the top of my head. This works as expected in the UnfortunateGuyDemo when placed at the end:

Code: Select all

            torso.BecomeKinematic();
            Vector3 offset = new Vector3(5, 5, 0);
            torso.Position += offset;
            upperArm.Position += offset;
            lowerArm.Position += offset;
            hand.Position += offset;
Joints transform local space data by the current connected entities' information each frame, and also recalculate their physical information each frame. Changing an object to kinematic or moving them together shouldn't be an issue.

A constraint cannot be connected to only kinematic entities though- that would usually cause an exception (and from the sounds of it, you're making only the torso kinematic to position the character pre-launch, so this won't be a problem).

It sounds like the transformation is being applied incorrectly somehow, like the translations are being rotated first.
NetSavant
Posts: 28
Joined: Wed Apr 20, 2011 10:50 pm

Re: Lag in joints attached to a kinematic

Post by NetSavant »

Thanks - you're right, I had something screwy with how I was saving & restoring initial limb transforms. Got the teleport working good now.

Need to get myself a proper linear algebra background, I waste too much time figuring out these transforms...
Post Reply