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);
@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 !
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.
Okay, 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
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â?
its created in jmonkeybuilder with these properties
Hmm, Iâve never used jmonkeybuilder.
So it does not generate any actual source code?
No it doensot .
Iâm thinking it potentially is a jmonkeybuilder bug.
Though, it is not maintained anymore⌠it is worth filing a bug report.
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
It looks to me like your collision mesh isnât scaled to the same scale as your heightmap.
@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).
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 !
Try 65 and 257 for your heightmap and total size.