Sunk Models

Hi!



I am having a problem getting my model to correctly walk over the top of my terrain properly. The normal action is for the model to sink into the higher regions of terrain, bit annoying really.



A picture of this is here:



http://img526.imageshack.us/my.php?image=problemrp3.jpg



Notice the legs sitting in the terrain.



Now. The initial position for the model is set as follows:



(I am using a heightmap for terrain btw):



enemy.setLocalTranslation(new Vector3f(1280,tb.getHeight(64, 64)+50, 1280));



and in the main update loop I am running this in a failing attempt to get the character to sit nicely about terrain when its being animated.:



if(enemy.getLocalTranslation().y <= (tb.getHeight(enemy.getLocalTranslation()))) {
            enemy.getLocalTranslation().y = tb.getHeight(enemy.getLocalTranslation());
            enemy.updateWorldVectors();
            enemy.updateRenderState();
            enemy.updateWorldBound();
        }



Please help!

Andy

In the initial position, you are using 64,64 as the position in your terrainblock, while placing it at local translation 1280,1280. In the update you are using the local translation directly as the position in the terrain block.

Is this as intended?



Also, in the initial positioning, you are adding 50 to the height, whereas in the update you are not?

This offset may be because the model is positioned about it's center, not it's feet?



Also, you hint that the model is animated, in which case it is probable that the feet move relative to the object. This would be more complex to account for but probably not cause such large discrepancies (though it is hard to tell how large they are from that screenshot).

Well the extra 50 is because it is positioned at its center, and the 50 moves it higher so it sits on the terrain.



What do you suggest I do?

You need at least to do the same thing in your update:



enemy.getLocalTranslation().y = tb.getHeight(enemy.getLocalTranslation()) + 50;



Nope - the model still runs along up to her feet in terrain … :expressionless:

Do you mean that the change made no visible difference? Or that it made a difference but did not solve the problem completely?

no visible difference, - i must admit im surprised at how this has to be done manually, in other engines, you simple apply an animator and then some gravity and this is done for you :S

Well, having the engine do something for you is not necessarily desirable. There is always a choice to be made between how much effort you want to put in versus how much freedom you want.



Anyway, if adding a constant to the position makes no difference it sounds like something else is wrong.

I would check the obvious things like is that statement ever actually getting executed, is the enemy being positioned again somewhere else in your code, etc.

hmm.



if(enemy.getLocalTranslation().y - 75 <= (tb.getHeight(enemy.getLocalTranslation()))) {
         System.out.println("woof woof woof");
            enemy.getLocalTranslation().y = tb.getHeight(enemy.getLocalTranslation());
            //enemy.getLocalTranslation().y = tb.getHeight(enemy.getLocalTranslation()) + 50;
            enemy.updateWorldVectors();
            enemy.updateRenderState();
            enemy.updateWorldBound();
        }



If getLocalTranslation returns the very center of the model associated with the node, then i will need to include this in the calculations, because its not the center we are worried about, its the feet, surely?

Does this sound right? If this is the case, how do I workout how tall my model is and discount it :S

oo

Maybe it's cos when I set the position as like 1280 , tb.getheight etc the x and z

Coords dnt match the height of the y value - I'm using a heightmap so how do I figure where

My x and z coords are based on the tb.getheight params.



Basicaly I think I'm getting the height of a different part of terrain and placing the model at the wrong x and z

Coords respectively

It will interpolate for you, as long as you set the step scale in the constructor.

So a 128x128 map with a step scale of 10 would mean 1280,1280 is the corner now 128,128.



You are right about needing to account for the feet offset in the if statement, still need to do it in the set aswell though (noticed it's commented out in the snippet).