[SOLVED] lookAt()?

quick q on facing two geoms to look at each other, even when the other moves.



shouldn't placing the code bellow in the simpleUpdate method force the two geoms to look at each other, even when one of them is moving in any of the three axis



currently it only switches the second geom to look at the first when the app is first started



 //Look at each other
        rootNode.getChild("p1").getLocalRotation().lookAt(rootNode.getChild("p2").getLocalTranslation(), Vector3f.UNIT_Y);
        rootNode.getChild("p2").getLocalRotation().lookAt(rootNode.getChild("p1").getLocalTranslation(), Vector3f.UNIT_Y);
    

When i add the line bellow the two models start responding to the lookAt statement. A matter of fact they seem a bit symmetrical; however, the intended response was to get the node to look at the moving node in the X and Z axis. With the current impl the second node moves with the first one(obviously) and if the player is on the opposite side of the ship it flips downside-up.



rootNode.getChild("p2").setLocalTranslation(rootNode.getChild("p1").getLocalTranslation().getX(),
               rootNode.getChild("p1").getLocalTranslation().getY(),
               rootNode.getChild("p1").getLocalTranslation().getZ()*-1f);



EDIT
okay by adding the line bellow p2 moves and looks at p1 but p1 only looks forward...What is happening lol even when I called updateGeometricState and updateModelState nothing happened why do I have to call a method to get values from itself before their is any reaction at all -_-


rootNode.getChild("p2").setLocalTranslation( rootNode.getChild("p2").getLocalTranslation());
rootNode.getChild("p1").setLocalTranslation( rootNode.getChild("p1").getLocalTranslation());

the first parameter to lookAt() needs to be in world coordinates.



Try getWorldTranslation() instead of getLocalTranslation().

Maybe you need to updateWorldVectors() before acessing the WorldTranslation tho.

@Core-Dump: yeah i realized tht was a big issue and I tried that; however, I am still unable to get the desirable effects. Though i've accidentally created a lot of notable ones tht i can use later on.



i know this isn't tht hard i jst keep getting weird effects with w/e i try



btw using jME3 so no updateWorldVectors() explicit call though i've updated to geometric state

This seems to be the only way I can get it partially working however it is probably the worst way to implement it and also the second character on p2 turn completely around before p1 crosses p2 to the other side.



Quaternion p1r = rootNode.getChild("p1").getLocalRotation();
        Vector3f   p1t = rootNode.getChild("p1").getWorldTranslation();

        Quaternion p2r = rootNode.getChild("p2").getLocalRotation();
        Vector3f   p2t = rootNode.getChild("p2").getWorldTranslation();
        
        lookAt2(p1r,p2t, Vector3f.UNIT_Y);
        lookAt2(p2r,p1t, Vector3f.UNIT_Y);

        rootNode.getChild("p1").setLocalRotation(p1r);
        rootNode.getChild("p2").setLocalRotation(p2r);

        rootNode.updateGeometricState();
        rootNode.updateModelBound();



This way seems very unaffectionate, does anyone know a better solution


 public void lookAt2(Quaternion quat, Vector3f direction, Vector3f up) {
        direction.setY(0);
        TempVars vars = TempVars.get();
        assert vars.lock();
        vars.vect3.set( direction ).normalizeLocal();
        vars.vect1.set( up ).crossLocal( direction ).normalizeLocal();
        vars.vect2.set( direction ).crossLocal( vars.vect1 ).normalizeLocal();
        //vars.vect1.zero();
        //vars.vect2.zero();
         // vars.vect3.zero();
        quat.fromAxes( vars.vect1, vars.vect2, vars.vect3);
        assert vars.unlock();
    }



MODIFY

actually with the original lookAt code, which i think is about the same besides setting the y translation to 0, seems to turn the character early as well even when I updateBounds and the geometric states  


EDIT

ahh Momoko informed me that my real issue was due to the fact that i directly used the translation of the second object use in the lookAt Method of the first without first normalizing it and subtracting it from its own translation...

Bonechilla IM'd me and I helped him with this problem :slight_smile:

Next up is premium housecall service :stuck_out_tongue: