[SOLVED] How to add the terrain hills to physics

So, i have added a flat terrian to my scene & added that terrian to the physics space as if its a normal spatial but now i get this :

Have you followed how this demo?

FOR just the physics code:

Terrain,

TerrainQuad terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());
terrain.addControl(new RigidBodyControl(0));
bulletAppState.getPhysicsSpace().addAll(terrain);

Geometries,

Geometry sphere = new Geometry("cannonball", new Sphere(10, 10, r));
sphere.addControl(new RigidBodyControl(new SphereCollisionShape(r), 2));
bulletAppState.getPhysicsSpace().add(sphere);
1 Like

@ItsMike54
hi there, i have followed the example folder …the terrain section before & used those codes , i remember they gave me the same results , so i have tried them again & these are the results :

there is something i cannot understand about Terrain Hills !
as if the terrain physics size doesnot actually fits the terrain spatial size so there are gaps between objects & thier physical diemensions !

see those physics of those shapes are translated way bit more on x-axis

My first thought is that maybe there is something wrong with your code.

…but we can’t see it.

Alternatives left for us: guess 100 random unrelated things until you show us the code and clarify. Or: just wait.

1 Like

Okay, :sweat_smile: here’s the code:

TerrainQuad terrain=(TerrainQuad) rootNode.getChild("Mars Floor");
        RigidBodyControl terrainphysics=new RigidBodyControl(0);
        terrain.addControl(terrainphysics);
        physics.getPhysicsSpace().add(terrainphysics);

Terrain properties
image

The first thing that pops into my head is casting a TerrainQuad to a Node potentially might not work in this scenario. Can you also show the code that creates “Mars Floor”?

1 Like

its created in jmonkeybuilder with these properties
image

Hmm, I’ve never used jmonkeybuilder.

So it does not generate any actual source code?

1 Like

No it doensot .

1 Like

I’m thinking it potentially is a jmonkeybuilder bug.
Though, it is not maintained anymore… it is worth filing a bug report.

1 Like


the same problem occurs with JmonkeyEngine SDK netbeans build

1 Like

Thanks for testing with the SDK.
The problem is boiling down, its either a jME bug or your code.

I think we’ll have to keep guessing at an answer until we find one as Pspeed said.

First:
I think the issue is trying to cast a TerrainQuad to a Node.
Instead of using an editor that writes to a j3o, write the plain java source code (this will be difficult, but gotta make sure if it will work).
So rather than this,

TerrainQuad terrain=(TerrainQuad) rootNode.getChild("Mars Floor");

try this (the java equivalent of what you were putting in the editor),

TerrainQuad terrin = new TerrainQuad("terrain", 64, 256, heightmap.getHeightMap());
terrain.setLocked(false); // unlock it so we can edit the height
1 Like

It looks to me like your collision mesh isn’t scaled to the same scale as your heightmap.

3 Likes

@ItsMike54 thank you😃 I know this is very easy to do , but …you know what’s the benefit of terrain without hills & different surfaces so that’s the reason why I am using the terrain editor which is indeed creating hills & different surfaces from one terrain simply but the case …that those hills are not added totally to the physics

So , I need to declare the limit of the heightmap ?

I don’t know because you’ve shown no code. But if your heightmap is scaled - the collision mesh needs to be scaled, too.

If your heightmap goes to 50 high or whatever, set the scale of it to Vector3f(1,50,1).

1 Like

Great ! Let’s forget about my code , imagine I am making a trial project that is a scene contains just a terrain added from the jme scene composer & edited by jme terrain editor so the result is a terrain with raised hills without physics or anything …how could I add physics to this dude simply ?

I need to add the terrain hills to the physics space not the terrain only !!!

those must be joined !
Screenshot at 2020-08-14 15-23-41

Try 65 and 257 for your heightmap and total size.