Bypassing the heightmap mesh issue problems :I

Hello.

I’v tried to create a terrain using heightmap, but the character did not collide with it, even tho the character physicnode was a sphere.



So I read about it and learned that theres a problem with jme3 unabling me to use CompoundCollisionShape method to get the terrain.

So now I have either a heightfieldcollisionshape that doesnt collide or a CompoundCollisionShape that gives error.

As I understood it I could then do a bullet mesh of the whole map instead.

But as I do that I yet again fail to get any collision.



Heres my method trying to get a collidable physicnode of a heightmap:

[java]public static PhysicsNode loadTerrainPhysic(AssetManager assetManager,String tex){

ImageBasedHeightMap heightmap = null;

heightmap = getHeightMap(tex, assetManager);

heightmap.load();

TerrainQuad terrain = new TerrainQuad(“my terrain”,

65, // tile size

513, // block size

heightmap.getHeightMap()); // heightmap



HeightfieldCollisionShape terrains = new HeightfieldCollisionShape(heightmap.getHeightMap());

//CompoundCollisionShape terrains = CollisionShapeFactory.createMeshCompoundShape((Node) terrain);



MeshCollisionShape terrainShape = new MeshCollisionShape();

terrainShape.setCShape(terrains.getCShape());

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







return landscape;

}[/java]

Why are you using MeshCollisionShape for the terrain? What i know about mesh collision shapes is that they don’t collide.

Well its because HeightFieldCollisionShape does not collide either.

And Compound collision gives an unremovable error.



Dunno what to use :frowning:

Hmm! @Normen modified the CollisionShapeFactory.createMeshShape(Spatial spatial) method to create HeightFieldCollisionShape if the spatial param instace of TerrainQuad, then you could use this method. The “create/update mesh shape” button of the Scene Composer Window also do it. Thank @Normen ;).

Great! Now only one small problem remains :smiley:

To know if my character is in the air, aka jumping, I use a ray to see if there is any object Under my charactersphere physic object.



Now apparently doing this:

[java]private int getCollision() {

CollisionResults results = new CollisionResults();

Ray ray = new Ray(this.physicsCharacter.getLocalTranslation(), Vector3f.UNIT_Y.mult(-1));

ray.limit = 1.2f;

MainClass.world.getRootNode().updateGeometricState();

MainClass.world.getRootNode().collideWith(ray, results);



return results.size();

}[/java]

when the character is standing on the height map will return 1.

Which is the character sphere itself.



If it does collide with the terrain then it should return 2, but it doesnt, even tho I see the character standing on the ground.



Why is that?

I did actually add the terrainnode to the physicsspace AND the rootNode…

You’re simply ignoring the jbullet recourses. You shouldn’t use CollisionResults for PhysicsCollisionObjects, this is a big waste. You should use CollisionResults for non-physics collision objects. If you wanna check collisions of your physics collision objects you should use PhysicsCollisionListener and PhysicsCollisionGroupListener. Just create a JME3 Tests project and look at the jme3test.bullet.TestCollisionListener example ;).

1 Like

Thank you very much glaucomardano, You’v been a great help :smiley:

Now it all works!

Thanks :smiley: