Model Floating Above Terrain

Hey Guys!



I have a Player class (in the code below, i.e. "this"), which contains a spatial with a model loaded into it. I am attempting to get the player model (tank) to "hug" the terrain. Having been through some of the tutorials I have:



      // Calculate the minimum height that the CHARACTER can be at without
      // being under the terrain
      float characterMinHeight = TankGame.getApplication().getTerrainManager().getTerrain().getHeight(this.getLocalTranslation())+ ((BoundingBox) this.getWorldBound()).yExtent;
      // If the minimum character height is valid, and the character is below
      // it
      if (!Float.isInfinite(characterMinHeight) && !Float.isNaN(characterMinHeight)) {
         // Move the character above the terrain
         this.getLocalTranslation().y = characterMinHeight;
      }
      
      
      
      //Hug the terrain:
      Vector3f terrainNormal = new Vector3f();
      TankGame.getApplication().getTerrainManager().getTerrain().getSurfaceNormal(this.getLocalTranslation(), terrainNormal);
      this.rotateUpTo(terrainNormal);



This seems to work pretty well, however the tank hugs about 2 foot above the terrain:



I'm sure I'm missing something pretty obvious here... any thoughts?

Try not adding the yExtent of your character…  your model probably "sits on" the origin rather than being centered at it.

Perfect!!! Thanks for your help!