Just another rotation problem :)

Hey everyone,



Ive got a new rotation problem (jme3) :slight_smile:



in my update method, Im moving and rotating my object to its "moveposition"



It works fine for all directions except them moving only in -z direction then my object looks in the wrong direction.



can someone tell me what Im doing wrong? I tried to find a topic for this problem but I didnt find one.






   if (movepositon != null)
      {
         final Vector3f subtract = movepositon.subtract(position);
         direction.set(subtract.normalize());

         position.addLocal(direction.mult(tpf * 3));
         mesh.setLocalTranslation(position);

         final Vector3f left = mesh.getLocalRotation().getRotationColumn(0);
         final Vector3f up = mesh.getLocalRotation().getRotationColumn(1);
         Quaternion fromAxes = mesh.getLocalRotation().fromAxes(left, up, direction); // <- here is the error
         mesh.setLocalRotation(fromAxes);
      }




edit:
In this video you can see the bug in action sec 21-24 (the two imps on the right side)
http://www.youtube.com/watch?v=1Bl5TzjBlRA

does nobody know whats wrong here, or has the same problem? :frowning:

You're doing it a bit incorrectly: You're using the previous left value, if its pointing in the other direction, then your character might be facing 180 the opposite way you intend it to.

I assume that the up vector for all your characters is 0, 1, 0, so you can just take the cross product of the up(0,1,0) and direction vector to find the left vector.

Thanks, this solved the problem!