My Player falls through the terrain (jME3)

Hi,



My player objects falls through my terrain. Do you have any suggestions how to see what's going wrong ?



This is my code:



public class Player extends Entity  {

    public Player(AssetManager assetManager, Node parent, PhysicsSpace physicsSpace) {

        super(assetManager, parent, physicsSpace);



        Spatial snowboard = (Spatial) assetManager.loadModel("Models/player_1/player_1.mesh.xml");

        //float scale = 0.05f;

        //snowboard.scale(scale,scale,scale);



        CompoundCollisionShape snowboardShape = CollisionShapeFactory.createMeshCompoundShape((Node) snowboard);

        PhysicsNode physicsMesh=new PhysicsNode(snowboard,snowboardShape,1);



        physicsMesh.setFriction(0.1f);

        physicsMesh.setLocalTranslation(new Vector3f(0,30.0f,0));

        physicsMesh.updateGeometricState();

        physicsMesh.updateModelBound();



        getParent().attachChild(physicsMesh);

        getPhysicsSpace().add(physicsMesh);

    }



public class Terrain extends Entity {

    public Terrain(AssetManager assetManager, Node parent, PhysicsSpace physicsSpace) {

        super(assetManager, parent, physicsSpace);



        //com.jme3.terrain

        //BufferGeomap



        Spatial terrain = (Spatial) assetManager.loadModel("Models/terrain_1/terrain_1.mesh.xml");

        //Spatial terrain = (Spatial) assetManager.loadModel("Models/terrain_2/terrain_2.mesh.xml");

        float scale = 200.0f;

        terrain.scale(scale,scale,scale);

        terrain.updateGeometricState();

        terrain.updateModelBound();



        CompoundCollisionShape terrainShape = CollisionShapeFactory.createMeshCompoundShape((Node) terrain);

        PhysicsNode physicsMesh=new PhysicsNode(terrain,terrainShape,0);



        physicsMesh.setFriction(0.1f);

        physicsMesh.setLocalTranslation(new Vector3f(0,-60.0f,0));

        physicsMesh.updateGeometricState();

        physicsMesh.updateModelBound();



        getParent().attachChild(physicsMesh);

        getPhysicsSpace().add(physicsMesh);

    }



Thanks in advance.

Movable physics nodes cannot have mesh collision shapes, use another collision shape type for your player.

You could use a GImpact shape , but it is way slower than everything else you could use (like several boxes for hitzones in a compundshape)

Thanks. It works now.



I still got one question. How can I calculate the halfextends for the BoxCollisionShape ?



I now have this code:

        Spatial snowboard = (Spatial) assetManager.loadModel("Models/player_1/player_1.mesh.xml");

        PhysicsNode physicsBox=new PhysicsNode(snowboard,new BoxCollisionShape(new Vector3f(2, 2, 4)),1);

The halfextents is basically just a vector from the center of the box to one of its corners to define its size. You could assign a BoundingBox to the spatial and retrieve those values from there. A convenience method for that will be added to the CollisionShapeFactory sooner or later.

normen said:

The halfextents is basically just a vector from the center of the box to one of its corners to define its size. You could assign a BoundingBox to the spatial and retrieve those values from there. A convenience method for that will be added to the CollisionShapeFactory sooner or later.


Btw.. these convenience methods are working and ready in my working copy  :D
If you're ready, I'm ready, just let know.
tim8dev said:

Btw.. these convenience methods are working and ready in my working copy  :D
If you're ready, I'm ready, just let know.

Yeah, I moved your post to the contrib board along with some other nice things for the physics like heightmap collision shaoes etc. If you have added new stuff just post it to that thread, I will probably work on the physics again soon and then add all the contributions.

I have this code now, but my BoundingBox doesn't get the "extent" values:



        BoundingBox boundingBox = new BoundingBox();

        snowboard.setModelBound(boundingBox);

        snowboard.updateModelBound();



        //PhysicsNode physicsBox=new PhysicsNode(snowboard,new BoxCollisionShape(new Vector3f(2, 5, 2)),1);

        PhysicsNode physicsBox=new PhysicsNode(snowboard,new BoxCollisionShape(new Vector3f(boundingBox.getXExtent(), boundingBox.getYExtent(), boundingBox.getZExtent())),1);



Do you know what's going wrong ?



Thanks in advance.

Maybe try calling updateGeometricState() on the snowboard before.

It still doesn't work:



        BoundingBox boundingBox = new BoundingBox();

        snowboard.setModelBound(boundingBox);

        snowboard.updateGeometricState();

        snowboard.updateModelBound();



        //PhysicsNode physicsBox=new PhysicsNode(snowboard,new BoxCollisionShape(new Vector3f(2, 5, 2)),1);

        PhysicsNode physicsBox=new PhysicsNode(snowboard,new BoxCollisionShape(new Vector3f(boundingBox.getXExtent(), boundingBox.getYExtent(), boundingBox.getZExtent())),1);

[c0de]
Node col = LoaderThread.LoadRaw("truck_phys");
      col.updateGeometricState();
      col.updateModelBound();
      BoundingBox bound = (BoundingBox) col.getWorldBound();
      System.out.println(col.getTriangleCount() + " Size: " + bound.getExtent(null));