Trouble with lookAt and Model Direction

When I use this code the model seems to exist at three different angles.  Can anyone tell me what im doing wrong.  I just want the model to face the direction its moving and to stay above the terrian hightmap(tb).


protected void simpleUpdate() {

           if (tpf < 1) {

              x = x + (tpf10);

              z = z - (tpf

              if (x < 0 || x > 100){

                 x = 0;


              if (z < 0 || z > 100){

                 z = 100;



           float y = 0f;       

           float characterMinHeight = tb.getHeight(model


           if (!Float.isInfinite(characterMinHeight) && !Float.isNaN(characterMinHeight)) {

              y = characterMinHeight +12;


           Vector3f newLocation = new Vector3f(x,y,z);          

           model.lookAt(newLocation, Vector3f.UNIT_Y);          

           model.getLocalTranslation().x = x;

           model.getLocalTranslation().y = y;

           model.getLocalTranslation().z = z;

I would love to know how this is done also - i think a lot of spins around the way the model was made i.e which way it had pointed north etc.

Not sure if that's the case, but I think look at rotates object around his pivot/origin point, which means that if it is set in place different than the middle it will rotate it oddly. Whenever I'm modelling my stuff I tend to make sure their pivot is in the middle of them.

Anyway you can take a generic model and work out its origin, or just piovt it to the center?!

not sure what you mean by "When I use this code the model seems to exist at three different angles".

If your model is facing the wrong way when using lookat(), then you can do the following:

  • import your model
  • rotate it correctly
  • attach the correctly rotated to a new node to 'save' the rotation.
  • now only use this new node when using lookAt and moving the model around.

Ok…So using your own advice core dump = if i gave you this model :

Can you work out how to rotate it so that the bullet's tip is always pointing towards a target spatial - because I for sure cannot!


One possible reason for the problem is "up" vector.

The left, up, direction vector of the camera should be orthogonal each other.

If your direction vector's y value isn't 0 (in other words, the direction is not parallel to 'y=0' plane)

Vector3f.UNIT_Y is not proper value for up vector.

Alright, so if I have the .blend file for this object i can reset this for example?? I really have absolutely no idea about modelling etc which is why my games usually halt at points like this because I simply cannot work out how to fix such problems! :wink: