Model walking on terrain ... again!

Hi everybody

The subject says "again" because it's a kind of post I have already seen in the forum.

I have a JME model with his bounding box and I have a tiled terrain.

I have the world coordinates of the bottom of the boundig box and the world coordinates of the point on the terrain where the bottom must be placed.

So I calculate the world translation between the two points, but what I need is to translate the model and I can only change his local translation.

I'm sorry but I really didn't find an answer in the other posts on these subjects (WorldToLocal, …).

Could you help me, Monkey Fans ?

Spatial.worldToLocal(…) would help you if you really need to convert from world to local coordinate space. But do you need it? I could imagine that world and local coordinates are the same for this case as you most probably do not have a parent node that is transformed (scaled/translated/rotated), do you?

In fact, my model node himself is transformed. I had to chage his scale and I translate it to be over the terrain.

So when I translate it with the world translation I have calculated, it goes under the terrain.  :frowning:

Perhaps the problem come from my understanding of the node hierarchy in JME ?

Here is my code. I hope it can help.

BoundingBox vol = (BoundingBox)((TriMesh)freak.getNode().getChild(0)).getWorldBound();

Vector3f bottom = new Vector3f(vol.getCenter().subtract(0,vol.yExtent,0));

Vector3f position = new Vector3f(bottom.x,terrain.getHeight(bottom.x,bottom.z),bottom.z);

float calc = position.y-bottom.y;

Vector3f vtmp = new Vector3f(decal,calc,-decal);


Ok, I finally found a solution.

You were right Irrisor, if I scale the Trimesh and not the node, the translation works fine !

Thanks a lot.  XD