Teleporting a ragdoll while in ragdoll mode!

Hi!



This has troubled me since it began falling below the terrain.

Do you think something can be added in the ragdoll control to do the same?



This way I found is:

The idea is to have one bone as reference and move all linked relatively.

It also looks great as it moves exactly as it was before!



here:

[patch]

public static void teleportRagdoll(PhysicsRigidBody prbReference, Vector3f to){

Vector3f from = prbReference.getPhysicsLocation();

Vector3f relativeDisplacement = to.subtract(from);

teleportRagdollBone(null, prbReference, relativeDisplacement);

}



private static void teleportRagdollBone(PhysicsJoint skipJoint, PhysicsRigidBody prb, Vector3f relativeDisplacement){

// this is recursive self

prb.setPhysicsLocation(prb.getPhysicsLocation().add(relativeDisplacement));

for(PhysicsJoint p : prb.getJoints()){

if(p == skipJoint)

continue;

if(prb != p.getBodyA())

teleportRagdollBone(p, p.getBodyA(), relativeDisplacement);

if(prb != p.getBodyB())

teleportRagdollBone(p, p.getBodyB(), relativeDisplacement);

}

}

[/patch]



For Oto, you can set prbReference as getRagdoll().getJoint(“head”).getBodyB(). It will find all bones and move them with precision :smiley:

By convention the reference node is the root node.

I’m gonna try to find a way to make this work through model.setLocalTranslation, because it’s how it works in kinematic mode.



Thanks for the suggestion and the code

Done,

update to last svn revision, and you’ll be able to move the ragdoll in ragdoll mode using model.setLocalTranslation.

Worked perfectly, and even faster I guess, thx!