Problems with collisionshape

Hi,

I created a scenemodel including a collisionshape like in the hello collision tutorial. I created a Method that shoots a stone with a collisionshape when it is used but the problem is that stone goes through the walls of the scenemodel.

Has anybody an idea what the problem is?



Thanks in advance.

You did it wrong probably.

Maybe but I nearly copied the Code from the tutorials.

If this is supposed to be anything more than a naff conversation you will have to give us more info…

[java] public void createCurlingStein () {

//Stein laden, skalieren, positionieren, und an den rootNode anhängen

Spatial stein = (Spatial) assetManager.loadModel("Models/"

  • "Curlingsteingelb/GelberCurlingStein.mesh.xml");//Stein laden

    float scale = 0.005f; //Skalierungswert definieren

    stein.scale(scale, scale, scale); //stein-Model skalieren

    stein.setLocalTranslation(startPosition);//stein-Model positionieren

    //rootNode.attachChild(stein); //an den rootNode anhängen



    //PhysicsNode initialisieren

    curlingShape = new SphereCollisionShape(scale); //erstellt ein

    //CollisionShape für den

    //CurlingStein

    curlingShape.setMargin(scale);

    PhysicsNode steinNode = new PhysicsNode(

    stein, // Model für den der PhysicsNode gelten soll

    curlingShape, // collision shape das für den Stein gelten soll

    0.0f); // Masse des Objektes.

    steinNode.setRestitution(1.0f);







    //Schattenwurf definieren

    steinNode.setShadowMode(ShadowMode.CastAndReceive);



    //PhysicsNode an den rootNode anhängen

    this.rootNode.attachChild(steinNode);



    //PhysicsNode in den Physikalischen Raum des Spieles einbringen

    this.bulletAppState.getPhysicsSpace().add(steinNode);



    //Stein in Bewegung versetzen mit Angabe der Richtung

    //steinNode.setLinearVelocity(Vector3f.UNIT_X);

    steinNode.setMass(1.0f);

    steinNode.applyImpulse(Vector3f.UNIT_X.clone().mult(10), stein.getLocalTranslation());





    //FlyCam ausschalten

    flyCam.setEnabled(true);



    //ChaseCamera auf den Stein einstellen.

    // ChaseCamera chaseCam = new ChaseCamera(cam, stein, inputManager);

    // chaseCam.setSmoothMotion(true);

    }

    [/java]

    That´s the way I create the curlingstein,

    [java]

    sceneModel = assetManager.loadModel("Scenes/Bahn1/bahn1.j3o");

    sceneModel.setLocalScale(2f);

    CompoundCollisionShape sceneShape = CollisionShapeFactory.createMeshCompoundShape((Node) sceneModel);

    PhysicsNode scene = new PhysicsNode(sceneModel, sceneShape, 0);

    this.rootNode.attachChild(scene);

    this.bulletAppState.getPhysicsSpace().add(scene);

    [/java]

    This is the creation of the scene.

    In addition there is the global BulletAppState bulletAppState which is initialized in the simpleInitApp()

    with:

    [java]

    bulletAppState = new BulletAppState();

    stateManager.attach(bulletAppState);

    [/java]

Make sure your physic model(the static one) only contains one mesh and use the Meshshape then,



actaully from the name I guess what you are doing should work to, but I’m not sure as I never used that method.

If I understood the functionality of Collisionshape right then it gets a model and creates Collisionshapes of all childnodes of the model.

I might be wrong with that but that´s the way I understood it.

The scaling of the model doesnt seem to get applied, try using CollisionShapeFactory.createMeshShape();, it should update the scale before doing the collision shape.

I tried it but it goes straight through the wall as before. And another thing:

[java]

PhysicsNode steinNode = new PhysicsNode(

stein, // Model für den der PhysicsNode gelten soll

curlingShape, // collision shape das für den Stein gelten soll

1.0f); // Masse des Objektes.

steinNode.setRestitution(1.0f);



//Schattenwurf definieren

steinNode.setShadowMode(ShadowMode.CastAndReceive);



//PhysicsNode an den rootNode anhängen

this.rootNode.attachChild(steinNode);



//PhysicsNode in den Physikalischen Raum des Spieles einbringen

this.bulletAppState.getPhysicsSpace().add(steinNode);



//Stein in Bewegung versetzen mit Angabe der Richtung

steinNode.setLinearVelocity(Vector3f.UNIT_X);



[/java]

When i use this Method to throw the stone it flies in randomly moves through the room.

Is it possible that there is nothing wrong with code but with bulletAppState or the PhysicsSpace?

No, probably its your code. Do steinNode.attachDebugShape(assetManager); to see the actual collision shape, it will probably explain the “random movement”. Then try doing an .updateGeometricState() on the model after setting the scale (dont have the model attached to any node while doing that), as said the scale is not properly updated until the next render thread, so consider this a workaround until that is the case.

I did what you said but the it still does not work. the scale is correct in fact that the stone is smaller than i don´t scale it. When I do steinNode.attachDebugShape I don´t see a Collisionshape, might I done the initializesation of the shape the wrong way?

When I looked at the movement of stone some time I noticed that stone seems to circle around an axis, I don´t whether this helps to fix the problem.

Hm, yeah, your collision shape for the character only has a radius of 0.005f, thats 5millimeters, probably a bit under-sized for a character xD

Now i use a CylinderCollisionShape for the stone ( I think this better for this kind of object) When I use attachDebugShape on the SceneModel and stone I see both Shapes the problem is:

a) The Shape of the stone is some metres in front of stone itself,

b) the stoneShape does not collide with sceneShape it goes right through it.

Both shapes are attached to rootNode and PhysicsSpace, so I don´t understand what the problem is

Sorry that I´m pushing this topic but the problem is still not fixed. The problems are the same as in the post above, so please help me with these thing.

philippengel said:
a) The Shape of the stone is some metres in front of stone itself,


Make sure the stone's geometry(ies) is(are) centralized, and you only changed the local translation and local rotation of the stone physics node, and not of its children. You can to test your scenes with the "physics editor" :D, attaching debug shapes for your physics nodes. The physics editor still not save the opened scene.