in my search at my ragdoll/ physics problem I’ve created this class:
[java]/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package org.mvd.jme3.models.ragdoll;
import com.jme3.asset.AssetManager;
import com.jme3.bullet.PhysicsSpace;
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
import com.jme3.bullet.joints.PhysicsConeJoint;
import com.jme3.bullet.joints.PhysicsJoint;
import com.jme3.bullet.nodes.PhysicsNode;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
/**
*
-
@author maarten
*/
public class simpleRagdoll extends Node{
private PhysicsNode shoulders;
private AssetManager assetManager;
public simpleRagdoll(){
super();
createRagDoll();
}
public simpleRagdoll(String name){
super(name);
createRagDoll();
}
private void createRagDoll() {
shoulders = createLimb(0.2f, 1.0f, new Vector3f( 0.00f, 1.5f, 0), true);
PhysicsNode uArmL = createLimb(0.2f, 0.5f, new Vector3f(-0.75f, 0.8f, 0), false);
PhysicsNode uArmR = createLimb(0.2f, 0.5f, new Vector3f( 0.75f, 0.8f, 0), false);
PhysicsNode lArmL = createLimb(0.2f, 0.5f, new Vector3f(-0.75f,-0.2f, 0), false);
PhysicsNode lArmR = createLimb(0.2f, 0.5f, new Vector3f( 0.75f,-0.2f, 0), false);
PhysicsNode body = createLimb(0.2f, 1.0f, new Vector3f( 0.00f, 0.5f, 0), false);
PhysicsNode hips = createLimb(0.2f, 0.5f, new Vector3f( 0.00f,-0.5f, 0), true);
PhysicsNode uLegL = createLimb(0.2f, 0.5f, new Vector3f(-0.25f,-1.2f, 0), false);
PhysicsNode uLegR = createLimb(0.2f, 0.5f, new Vector3f( 0.25f,-1.2f, 0), false);
PhysicsNode lLegL = createLimb(0.2f, 0.5f, new Vector3f(-0.25f,-2.2f, 0), false);
PhysicsNode lLegR = createLimb(0.2f, 0.5f, new Vector3f( 0.25f,-2.2f, 0), false);
join(body, shoulders, new Vector3f(0f, 1.4f, 0));
join(body, hips, new Vector3f(0f, -0.5f, 0));
join(uArmL, shoulders, new Vector3f(-0.75f, 1.4f, 0));
join(uArmR, shoulders, new Vector3f(0.75f, 1.4f, 0));
join(uArmL, lArmL, new Vector3f(-0.75f, .4f, 0));
join(uArmR, lArmR, new Vector3f(0.75f, .4f, 0));
join(uLegL, hips, new Vector3f(-.25f, -0.5f, 0));
join(uLegR, hips, new Vector3f(.25f, -0.5f, 0));
join(uLegL, lLegL, new Vector3f(-.25f, -1.7f, 0));
join(uLegR, lLegR, new Vector3f(.25f, -1.7f, 0));
this.attachChild(shoulders);
this.attachChild(body);
this.attachChild(hips);
this.attachChild(uArmL);
this.attachChild(uArmR);
this.attachChild(lArmL);
this.attachChild(lArmR);
this.attachChild(uLegL);
this.attachChild(uLegR);
this.attachChild(lLegL);
this.attachChild(lLegR);
}
private PhysicsNode createLimb(float width, float height, Vector3f location, boolean rotate) {
int axis = rotate ? PhysicsSpace.AXIS_X : PhysicsSpace.AXIS_Y;
CapsuleCollisionShape shape = new CapsuleCollisionShape(width, height, axis);
PhysicsNode node = new PhysicsNode(shape);
node.setLocalTranslation(location);
return node;
}
private PhysicsJoint join(PhysicsNode A, PhysicsNode B, Vector3f connectionPoint) {
Vector3f pivotA = A.worldToLocal(connectionPoint, new Vector3f());
Vector3f pivotB = B.worldToLocal(connectionPoint, new Vector3f());
PhysicsConeJoint joint = new PhysicsConeJoint(A, B, pivotA, pivotB);
joint.setLimit(1f, 1f, 0);
return joint;
}
}
[/java]
(the important code is just stolen from the tutorials :p)
now when I call the code with this:
[java]Material mat1 = new Material(assetManager, “Common/MatDefs/Misc/SolidColor.j3md”);
mat1.setColor(“m_Color”, ColorRGBA.Blue);
ragdoll=new simpleRagdoll();
ragdoll.setMaterial(mat1);
ragdoll.setLocalTranslation(new Vector3f(0, 20, 0));
bulletAppState.getPhysicsSpace().addAll(ragdoll);
rootNode.attachChild(ragdoll);
[/java]
it does nothing.
I can’t see my pretty ragdoll and when I keep my camera at that ragdoll’s location it seems that physics on it doesn’t work.
So there should be something wrong with my code: it is not blue and it’s physics aren’t working.
someone that can spot my stupid mistake?