Problem: ray collision with terrain


I modified the HelloPicking tutorials with replacing the Geometry Cube for the floor by an heightmap. But when I trying to detect the collision between the ray and the new terrain nothing happens (of course, I adding the terrain to the shootables node).

[java]terrain = new TerrainQuad("ter", 65, 513, heightMap.getHeightMap());


terrain.setLocalTranslation(0, 0, 0);

terrain.setLocalScale(2f, 1f, 2f);

shootables = new Node("Shootables");



Can anyone know how to do that ?

Thanks for you answer !

Anyone to help me please ?

I have exactly the same problem. I downloaded the newest version (3.0beta) yesterday.

I create a flat terrain by passing an empty float array as hightmap:

[java] public TerrainQuad createTerrain() {

TerrainQuad terrain;

Material mat_terrain;

/** 1. Create terrain material and load four textures into it. /

mat_terrain = new Material(assetManager, "Common/MatDefs/Terrain/Terrain.j3md");

* 1.1) Add ALPHA map (for red-blue-green coded splat textures) /

mat_terrain.setTexture("m_Alpha", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));

* 1.2) Add GRASS texture into the red layer (m_Tex1). /

Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");


mat_terrain.setTexture("m_Tex1", grass);

mat_terrain.setFloat("m_Tex1Scale", 64f);

* 1.3) Add DIRT texture into the green layer (m_Tex2) /

Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");


mat_terrain.setTexture("m_Tex2", dirt);

mat_terrain.setFloat("m_Tex2Scale", 32f);

* 1.4) Add ROAD texture into the blue layer (m_Tex3) /

Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");


mat_terrain.setTexture("m_Tex3", rock);

mat_terrain.setFloat("m_Tex3Scale", 128f);

float[] heightmap = new float[10];

terrain = new TerrainQuad("my terrain", 65, 513, heightmap);

* 4. We give the terrain its material, position & scale it, and attach it. /



terrain.setLocalTranslation(0, 0, -10f);

terrain.setLocalScale(2f, 1f, 2f);

/** 5. The LOD (level of detail) depends on were the camera is: */

List<Camera> cameras = new ArrayList<Camera>();


TerrainLodControl control = new TerrainLodControl(terrain, cameras);


return terrain;


And i add them like the other objects in the MousePick Example:


Make sure to upgrade to the latest nightly build. There might be an old bug you are encountering.

I replaced the old libs with the new ones but it doesnt solve the problem.

does TerrainTestModifyHeight work for you?

When i execute the jMonkeyEngine3.jar which is in the NightlyBuild TerrainTestModifyHeight works but when i copy the source into my project the new imports who are in the jME3-terrain.jar are not found.

Is is not enaugh to copy the libs into libfolder and replace the old ones?

When i manualy add the jME3-terrain.jar to the projekt there are still some errors: (Uncompilable source code - no suitable constructor found for ImageBasedHeightMap(com.jme3.texture.Image,float)) ect so I think my update failed.

yea you have some old libraries floating around. How are you setting up your project? Are you using the SDK?

Yep, I’m using the SDK with standard Project settings.

you shouldn’t have to swap out any libs folders by hand, using the latest deploy will have those jars with it. You can try updating all of the plugins under Tools->plugins->updates. You also might have to delete your sdk directory and install it again, then import your project, if the jars aren’t properly getting replaced automatically.

Hm, i downloaded the SDK yesterday, it updated automaticly some files and today i copied the nightlyupdate jars into the lib folder of jmonkey but I will try it.

Ok, i fixed it by removing all old librarys from the projekt and adding the new ones.

Now i rotate the terrain in TerrainTestModifyHeight and it does not work anymone:


But why is the terrain normaly not in the XY-layer?

Yea don’t rotate terrain if you are going to use editing tools. I need to document that for use with tools: it isn’t supported.

@ogerlord said:
But why is the terrain normaly not in the XY-layer?

Most game engines are Z-up, and so is JME

oO Y-up!

sorry, I mean y-up. Dyslexic today :stuck_out_tongue:

Terrain’s points are on the XZ plane, with Y-up