I believe what I’m trying to accomplish is a much more watered down version of how a car’s wheels are managed by four rays cast down to the terrain.
I’m trying to have my obstacles cast a ray below it to detect the surface, and to keep casting every frame and check how far it is from the surface as well as what this new contact point is compared to the previous one.
However, my raycast collision only picks up the first one or two collisions and then says no collisions are occurring any more.
HERE is a video to demonstrate the issue.
The code I use is here:
Vector3f up_dir = Vector3f.UNIT_Y.mult(-1).clone();
//spatial.worldToLocal(Vector3f.UNIT_Y, up_dir);
Ray up_ray = new Ray(spatial.getLocalTranslation(),up_dir);
CollisionResults up_collisions = new CollisionResults();
track.collideWith(up_ray,up_collisions);
if(up_collisions.size() > 0){
CollisionResult up_closest = up_collisions.getClosestCollision();
Geometry m = mark.clone()
track.getParent().attachChild(m);
m.setLocalTranslation(spatial.localToWorld(up_closest.getContactPoint(),null));
System.out.println("Up dist: " + up_closest.getDistance() + up_closest.getGeometry().getName());
}
if(up_collisions.size() == 0) {
System.out.println("No up collisions");
}
I’m sure there is some underlying physics problem I’m not understanding. Or if I can do this in another way, do tell. This is the first way that came to my mind.
The logs show initial collisions on the tubes, and the no collisions. As the video demonstrates, there is that first registered mark, and then no more.
Any thoughts as to why?