[Question]How do i find the height of a model at a particular position?

im trying to make a model move on another model which is the ground in my game. both model are of type Spatial.

i cast a ray from the center of one model down and collect the pick results.



then i wanna find the ground model in the pickResults.



i found this in another post

TriMesh mesh = (TriMesh)results.getPickData(i).getTargetMesh();

but it doesnt allow me to cast GeomBatch to TriMesh or Spatial. i dont know how it worked for that guy~



basically this is what i wanna do.



      // Find the island model in the results.
      boolean found = false;
      Spatial model;
      for(int i = 0; i < results.getNumber() && found == false; i++)
      {
         model = (Spatial)results.getPickData(i).getTargetMesh();
         if(model.getName().equalsIgnoreCase(player.getIsland().getModel().getName()))
         {
            found = true;
         }
      }
      
      // Find the intersection.
      TriMesh mesh = (TriMesh) model;
      boolean hit = false;
      Vector3f[] vertices = new Vector3f[3];
      for(int i = 0; i < mesh.getTriangleCount() && hit == false; i++)
      {
         mesh.getTriangle(i, vertices);
         hit = ray.intersectWhere(
               vertices[0].addLocal(mesh.getWorldTranslation()),
                  vertices[1].addLocal(mesh.getWorldTranslation()),
                     vertices[2].addLocal(mesh.getWorldTranslation()), intersection);
      }

Take a look at jmetest.intersection.TestObjectWalking that might help you out.

mojomonk said:

Take a look at jmetest.intersection.TestObjectWalking that might help you out.


thx alot~i solved it.