CollisionShapes and Nodes in jbullet-jme

Hi all,



I've a problem with CollisionShapes. When I want to add a 3d model to my scene and surround it with a CollisionShape it seems always like the middle of the CollisionShape is on the "ground" of the Node so every model stands a piece abouve the Ground and not on the Ground.



I searched the forum but doesn't find a solution so has anybody an idea?



My Code for an example:


Node model =null;
        try {
            model = (Node) BinaryImporter.getInstance().load(new File(System.getProperty("user.dir")+"/models    /run/run.jbin"));
        } catch (IOException ex) {
            Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex);
        }
        model.setLocalScale(0.05f);
        model.setModelBound(new BoundingSphere());
        model.updateModelBound();
        model.updateWorldBound();
      
        model.getController(0).setActive(false);
        model.updateGeometricState(0, true);

        SphereCollisionShape shape = new SphereCollisionShape(model);


        character=new PhysicsCharacterNode(model, shape, .1f);
        character.setLocalTranslation(0,3,0);
        state.getRootNode().attachChild(character);
        character.updateRenderState();
        pSpace.add(character);

After setting the collisionshape, call attachDebugShape(assetManager) on the node to see the collisionshape, then the problem should become apparent.

Cheers,

Normen

wow, that was a quick reply, thanks!



could it be that the function is from jme3? I'm using jme2 and can't find the function attachDebugShape(assetManager)    :smiley:

Bastard said:

wow, that was a quick reply, thanks!

could it be that the function is from jme3? I'm using jme2 and can't find the function attachDebugShape(assetManager)     :D

Yes it is, the debug view works differently in jme2. Theres a test example how to set it up.

ok, I get it. Thanks very much, it works with "normal" PhysicsNodes but do you have an idea what I can do for PhysicsCharacterNode? Cause this Node needs a SphereCollisionShape!

Bastard said:

ok, I get it. Thanks very much, it works with "normal" PhysicsNodes but do you have an idea what I can do for PhysicsCharacterNode? Cause this Node needs a SphereCollisionShape!

Huh? I dont understand? Yes, characters in the jme2 version of the library can only have sphere collision shapes.

Ok, maybe I should more explain. To get the PhysicsNode on the ground I've used a CompoundCollisionShape because I can position this Shape. But I can't use the CompoundCollisionShape for a PhysicsCharacterNode and so here my question: Is there another solution for this?

Bastard said:

Ok, maybe I should more explain. To get the PhysicsNode on the ground I've used a CompoundCollisionShape because I can position this Shape. But I can't use the CompoundCollisionShape for a PhysicsCharacterNode and so here my question: Is there another solution for this?

Move the child shape (model) so it is in the center of the sphere?

Thanks normen,



I've tried it always with translate the model before creating the CollisionShape, now after the creation it works.



For everybody who has the same problem:


        SphereCollisionShape shape = new SphereCollisionShape(model);
        model.setLocalTranslation(0, shape.getCShape().getMargin()*-1, 0);

Please dont use the getCShape() method, it will only return a long when the physics go native.

Is there any other posibillity to get the size or extent of the CollisionShape to translate the model?  :?

Bastard said:

Is there any other posibillity to get the size or extent of the CollisionShape to translate the model?  :?

No, but you know your values now :P I guess I should add that method to CollisionShape.
Cheers,
Normen

damn, ok thanks normen

Bastard said:

damn, ok thanks normen

Added to svn version