Hi!
I managed to make my zombies skeleton become a ragdoll when I press t.
Problem is: He is walking, and when I press t he ends up in the original “rest position”.
The one that you have in blender when editing the clothes etc.
So I would like to know how to fix that…
How do I create it?
The zombie Is created here:
[java]public Zombie(){
CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1f,3.2f, 1);
body = new CharacterControl(capsuleShape, .2f);
body.setMaxSlope((float) (Math.PI));
body.setJumpSpeed(20);
body.setFallSpeed(40);
body.setGravity(30);
piv = new Node(“Piv”);
Spatial shape = null;
if (hd){
shape = ShapeManager.ShapeMesh(“Zombie_2”, “Zombie_1.png”);
animationControl = new AnimationControl((Node)shape);
animationControl.setAnimation(“Walk”);
shape.setLocalTranslation(0,0,0);
shape.scale(0.75f);
} else {
shape = ShapeManager.ShapeBox(1, 2, 1, “Zombie.png”);
}
shape.setName(“Zombie”);
geo = shape;
shape.updateGeometricState();
MainClass.getRoot().attachChild(shape);
piv.attachChild(shape);
shape.addControl(body);
//MainClass.getRoot().attachChild(shape);
MainClass.getRoot().attachChild(piv);
MainClass.getPhysics().add(body);
body.setPhysicsLocation(new Vector3f(20, 30, 0));
}[/java]
Then when he gets hit the following executes:
[java]public void damage(int hp) {
this.hp -= hp;
geo.removeControl(body);
//piv.detachChild(geo);
//MainClass.getRoot().attachChild(geo);
//geo.setLocalTranslation(body.getPhysicsLocation());
setupRagdoll();
ragdoll.setRagdollMode();
}
private void setupRagdoll() {
ragdoll = new KinematicRagdollControl(0.5f);
ragdoll.addBoneName(“Torso.Top”);
ragdoll.addBoneName(“Torso.Bottom”);
ragdoll.addBoneName(“MainBone”);
ragdoll.addBoneName(“Butt.R”);
ragdoll.addBoneName(“Butt.L”);
ragdoll.addBoneName(“Shin.R”);
ragdoll.addBoneName(“Shin.L”);
ragdoll.addBoneName(“Hip.R”);
ragdoll.addBoneName(“Hip.L”);
ragdoll.addBoneName(“Heel.R”);
ragdoll.addBoneName(“Heel.L”);
ragdoll.addBoneName(“Foot.R”);
ragdoll.addBoneName(“Foot.L”);
ragdoll.addBoneName(“Shoulder.R”);
ragdoll.addBoneName(“Shoulder.L”);
ragdoll.addBoneName(“Arm.R”);
ragdoll.addBoneName(“Arm.L”);
ragdoll.addBoneName(“Forearm.R”);
ragdoll.addBoneName(“Forearm.L”);
ragdoll.addBoneName(“Hand.R”);
ragdoll.addBoneName(“Hand.L”);
ragdoll.addBoneName(“Fingers.R”);
ragdoll.addBoneName(“Fingers.L”);
ragdoll.addBoneName(“Neck.Bottom”);
ragdoll.addBoneName(“Neck.Top”);
float eighth_pi = FastMath.PI * 0.0125f;
ragdoll.setJointLimit(“Torso.Top”, eighth_pi, eighth_pi, eighth_pi, eighth_pi, eighth_pi, eighth_pi);
ragdoll.setJointLimit(“Torso.Bottom”, eighth_pi, eighth_pi, 0, 0, eighth_pi, eighth_pi);
ragdoll.addCollisionListener(new RagdollListener(this));
geo.addControl(ragdoll);
MainClass.getPhysics().add(ragdoll);
}
[/java]
Not sure what Im doing wrong as this is the only way for me to get it working… All help appriciate
Don’t setup the ragdoll each time the zombie takes damage.
Do it in a initialization phase and just enable the ragdollMode when hit.
That’s probably not the issue, but it will be faster.
Then i don’t really get what you mean by “he ends up in the rest position”. You mean he doesn’t fall?
Maybe a video could help.
Setting it up before, then when he get hurt I do:
[java]geo.removeControl(body);
geo.addControl(ragdoll);
piv.detachChild(geo);
MainClass.getRoot().attachChild(geo);
geo.setLocalTranslation(body.getPhysicsLocation());
ragdoll.setRagdollMode();[/java]
And the character does not even move. He stays in rest-position.
With restposition I meen arms out stretched, standing up forming a cross.
Its how the armature would be unless it was animated. Makes it easier to assign clothes etc.
So, any idea what im doing wrong?
Nvm, now I got it working.
Looks somewhat odd when he appears to be quite flat when he hit the ground but Ohwell
Soon Ill upload a youtube video on my game so far and post it here