Something like getLocalHeight(x,z) for Spatials

Hi there,

currently I am trying walking around with my character in on a terrain. That works fine as I can

update the height at every step with terrain's getHeight(…)-method.

But I build a cool bridge-model that leads over a river. But now the question, is there a way to

get something like the local height of a certain x,z-position inside a spatial equal to the getHeight of

terrainpage? Or another possibility? If not my approach would be to see if there is a collision with the

bridge and increase the character's height until there is no collision anymore. But that is not elegant and

will for sure make problems as I use an animated character.

I would be very happy if someone could help me.

Thx, ToM

Ok…I found it out how to achieve it.

There was an example that helped me a lot (TestObjectWalking from the Intersection-Tests).

1)You need to put all elements you want to walk on in a special node.

2)You have a Ray pointing down from your location.

3)Every step you move check if a pick gets a collision.

4) get the triangle you walked on.

5) adjust y-value

(Hint:add the terrain at last to the end the method takes the first pick's y-pos! so this have to be modified

but I have no time for that now)

This is how it looked for me. It is more or less the same like in the TestObjectWalking:

class MyNode extends Node
       Ray ray = new Ray(new Vector3f(), new Vector3f(0,-1,0));

       public void doStep()
      nodeWithAllElementsToWalkON.calculatePick(ray, camResults);   
   TrianglePickResults camResults = new TrianglePickResults() {

      public void processPick() {
         //initialize selection triangles, this can go across multiple target
         int total = 0;
         for(int i = 0; i < getNumber(); i++) {
            total += getPickData(i).getTargetTris().size();
         if (getNumber() > 0) {
               PickData pData = getPickData(0);
               ArrayList<Integer> tris = pData.getTargetTris();
                   TriMesh mesh = (TriMesh) pData.getTargetMesh();
               if(tris.size() > 0) {   
                  int triIndex = ((Integer) tris.get(0)).intValue();
                  Vector3f[] vec = new Vector3f[3];
                  mesh.getTriangle(triIndex, vec);
                  for(int x = 0; x < vec.length; x++) {
                     mesh.getWorldRotation().mult(vec[x], vec[x]);
                  Vector3f loc = new Vector3f();
                  pData.getRay().intersectWhere(vec[0], vec[1], vec[2], loc);