Are you doing any translations or other transforms on your terrain? From your last picture, it looks like the coordinate system of the physics space is shifted relative the coordinate system of your scene. Both the terrain itself and the physics object must have the same transforms applied (though the physics controls should take care of this).
You have emphasized my complain but No,translations seem to be made automatically by the editor as i thought of it as an issue,when i used plain java code , it works but i need the editor for other stuff placed on that terrain ,i amnot going to make an empty terrain with physics & random heights displacement , i need to find a solution for the jmonkeyBuilder scene editor, this is a project not a simple test so i donot need to write everything down even the simplest in code
Place all the objects into the same node and use that node for your physics control.
Edit: There must be a way to access/change variables manually as @javasabr would not leave something like that out I am sure.
Edit: Opps on reply to @danielp
TerrainQuad marsFloor=new TerrainQuad("Mars Floor", 250, 1025, null);
marsFloor.setMaterial(new Material(assetManager, "Common/MatDefs/Terrain/Terrain.j3md"));
marsFloor.setHeight(new Vector2f(0f,10f), 5);
rootNode.attachChild(marsFloor);
RigidBodyControl rigidBodyControl = new RigidBodyControl(0);
marsFloor.addControl(rigidBodyControl);
physics.getPhysicsSpace().add(marsFloor);
why using a terrainquad of total size 1025 with patch size 250 drops FPS downTO 12 & 10 frames
Placed the terrain to the node & added node to physics , but the same problem occurs concerning the terrain editros
this code works fine , the terrain fits its physics & hills are added too so the problem with using code is dropping FPS
I have created a new scene **
WITH DIFFERENT NAME(THIS IS IMPORTANT,& I DONOT KNOW WHY)
**, imported my Hover Tank into it & created a new Terrain with any property(total size & patch size) in JMonkeyBuilder & added some heights using terrain editor pointer & added to the physics as any normal spatial & it works ,
& finally it works successfully ,
SO THE PROBLEM WASNOT WITH THE CODE AS THERE’s NO CODE , ITS WITH EDITOR , SOMETHING WRONG I HAVE MADE WHEN THE SCENE WAS WITH FILENAME Mars.j3o & there HAS BEEN A CACHE FILE FOR THIS Mars.j3o which is not overwritten by default when i create a new scene with the same name , so the editor has bugs with overriding cache files by default
the selected folder here seems to be holding cache files or database for workspace settings
the code is simply any spatial~physics code can handle this , my code:
public void addRigidShape(String nodeName, float mass, Vector3f gravity) {
Spatial spatial = rootNode.getChild(nodeName);
RigidBodyControl rigidBodyControl = new RigidBodyControl(CollisionShapeFactory.createBoxShape(spatial),mass);
spatial.addControl(rigidBodyControl);
physics.getPhysicsSpace().add(rigidBodyControl);
}
Im a bit rusty on physics but I think this is what you need.
https://javadoc.jmonkeyengine.org/v3.3.2-stable/com/jme3/terrain/geomipmap/TerrainQuad.html
Patch size can be specified on the terrain. This sets how large each geometry (TerrainPatch) is. It also must be a power of 2 plus 1 so the terrain can be subdivided equally.
Use this on your node that has both flat terrain and mountains attached.
https://javadoc.jmonkeyengine.org/v3.3.2-stable/com/jme3/bullet/util/CollisionShapeFactory.html
createMeshShape(Spatial)
https://wiki.jmonkeyengine.org/docs/3.2/physics/physics.html#collisionshape-code-samples
Then use the collisionShape with your control.
Then add the control to your node.
Actually , i have revised Java Doc for TerrainQuad & now i know all of its code , but this line is a little bit confusing , so what’s meant by this line ?
257 not 250
256+1
yes,better said it must have a square root,
what’s 1 then ?
Might want to read those links.
Each point in the terrain is one unit apart from its neighbour.