Hello monkeys,
I am relatively new to JME, but I suspect I may have found a bug, or I’m missing something stupid.
I have a Sphere floating above a terrainquad, moving with vector (1, 0, 0). The terrain quad is made from a hill height map, but not very hilly at all, nearly flat with rolling hills.
I am using a ray casting technique similar to @norman’s video tutorial on Don Quixote.
Problem: When I cast an infinite ray from the sphere’s position, (sphere.getLocalTranslation()), direction (0,-1,0), it finds a collision, but always at (0,0,0).
Based on this topic: http://hub.jmonkeyengine.org/forum/topic/terrain-ray-collision/ , I tried altering the direction to (new Vector3f(0.0000001f, -1, 0)).normalize(), and magically, it started working as intended.
Here is code working, only difference is the 0.00000001f --> 0f:
Thanks Monkeys!
[java]
if (terrain != null) {
Ray ray = new Ray(spatial.getLocalTranslation(), (new Vector3f(0.00001f, -1, 0)).normalize());
System.out.println("Ray "+ ray.origin+ ray.direction+ ray.limit);
CollisionResults results = new CollisionResults();
terrain.collideWith(ray, results);
for (CollisionResult result : results) {
Vector3f loc = result.getContactPoint();
spatial.getLocalTranslation().setY(loc.y);
System.out.println(loc.toString());
System.out.println(results.size());
}
}
else {
throw new IllegalArgumentException("Terrain not initialized for control");
}
[/java]