Terrain Ray Collision


I have been using the jME3 SDK for awhile now - admittedly in my ‘spare’ time, and I want to start off with saying how much I appreciate all the effort everyone on the development team has put into the project. I think the engine is well written and designed.

I have been trying to get terrain collision with rays to work. Here is my specific scenario:

  1. I created a simple 256x256 flat terrain in the SDK (create New JME Scene -> Add Spatial -> Terrain)
  2. I translate the terrain down 25 units
  3. I create a Ray 1000 units up pointing down (I wondered if there were some issues where the Ray origin was inside the bounding box )
  4. I do a terrain.collideWith(Ray, Results)

The test code (this is all the game is doing at this point):

The output:

The results always seem to return the collision point at (0.0, 0.0, 0.0). I have even tossed a translation on the terrain in the update loop and the collision point never changes. I have looked over manyforum posts on the subject and so far cannot find the problem with my simple code (the Ray direction vector is normalized). I have also looked at the TerrainTestCollision file (it does appear to use a Ray in the same situation I am) but it uses a terrain generated from a heightmap - is the SDK terrain the problem?

Am I doing something stupid? :slight_smile:

SDK terrain is just regular terrain, uses the same code.
You will have to post your code.

I posted all the code in the ‘game’ (it’s really just a test at this point). All it does is load the freshly created flat terrain and attempt to intersect a Ray with it as shown. I feel like I’m missing something obvious. Do I need to do anything other than assetManager.loadModel(“terrain_model_file.j3o”) and attach it to the root node?

If I add a light to the scene the terrain does show up but it gives the same collision result. For debugging I tried to keep the code as simple as possible.

Well I don’t know that I can say I figured out the problem per se - but the issue appears when the Ray is normal to the terrain. With the flat terrain and a Z-aligned Ray it didn’t return the collision results right in my simple test. When I shifted the Ray vector ever so slightly it calculated the collision point just fine.

Just thought I’d post in case anyone else ran across this.

It may be related to this:

Yes sometimes rays were not happy with zero volume bounding boxes, however I believe that was fixed ages ago. I had to put in a fix for terrain to handle that case.
I tested perpendicular rays to the terrain just now and they collide fine. What version are you using?