Use Case: have a sphere with a control that keeps it on top of Terrain as it moves accross Terrain
I am following Norman’s old youtube video on don quixote. It works fine while for awhile but as soon as it switches to a new patch of the terrain it moves to 0 on the Y like it can no longer see the Terrain.
I am having issue when it moves from one patch to the next. When it hits Patch 2 it shoots up to 0
Geometry Name 2 : myTerrainQuad4Quad1Patch3 Loc Y-72.73636
Geometry Name 2 : myTerrainQuad4Quad1Patch3 Loc Y-72.81961
Geometry Name 2 : myTerrainQuad4Quad1Patch3 Loc Y-72.90274
Geometry Name 2 : myTerrainQuad4Quad1Patch3 Loc Y-72.986084
Geometry Name 2 : myTerrainQuad3Quad4Patch2 Loc Y0.0
Geometry Name 2 : myTerrainQuad3Quad4Patch2 Loc Y0.0
Geometry Name 2 : myTerrainQuad3Quad4Patch2 Loc Y0.0
Code
EntityControl
public class EntityControl extends AbstractControl {
private long speed = 10;
@Override
protected void controlUpdate(float tpf) {
spatial.move(tpf*speed, 0, 0);
}
TerrainTrackControl
public class TerrainTrackControl extends AbstractControl {
private final Ray ray = new Ray(Vector3f.ZERO.clone(), new Vector3f(0,-1,0));
private final Vector3f up = new Vector3f(0,400,0);
private final CollisionResults results = new CollisionResults();
private Spatial terrain;
private float offset = 2f; //sphere radius
@Override
protected void controlUpdate(float tpf) {
terrain = spatial.getParent();
if(terrain!=null){
ray.setOrigin(spatial.getWorldTranslation().add(up));
ray.setLimit(400);
results.clear();
terrain.collideWith(ray, results);
for(Iterator<CollisionResult> it = results.iterator(); it.hasNext();){
CollisionResult collisionResult = it.next();
if(isTerrain(collisionResult.getGeometry())){
Vector3f loc = collisionResult.getContactPoint();
System.out.println("Geometry Name 2 : " + collisionResult.getGeometry().getName() + " Loc Y" + loc.getY());
spatial.setLocalTranslation(spatial.getLocalTranslation().setY(loc.getY() + offset));
return;
}
}
}
}
private boolean isTerrain(Spatial spatial) {
while(true) {
if(spatial == null) {
return false;
}else if(TestTerrian.TERRAIN_NAME.equals(spatial.getName())) {
return true;
}
spatial = spatial.getParent();
}
}
What did I miss?