Opponent facing to player

                enemyNode.lookAt(characterNode.getLocalTranslation(), Vector3f.UNIT_Y); // watching player
                Quaternion rotateEnd = enemyNode.getLocalRotation(); // Final rotation;
                if (tick < 1) {
                    tick += 1;

Hi guys. I did such the thing. It have to set enemy towards player and to be updated every main loop. Somewhere else i put tick=0; to reset counter. Unfortunately it makes enemy is spinning every time when I touch the screen ( game is for android ). How to deal with such the issue ? Thanks a lot


You are directly modifying the rotation you just got from the enemyNode… this will cause strange results unless you clone it first or even better, just don’t call multLocal but mult:
rotateEnd = rotateEnd.mult(enemyViewDirection);


Hmm… the only change is that enemy is doing nothing :thinking:


When code starts, initially enemy get proper rotation. Then tick=0 - when move==true should trigger the another rotation. But this rotation lasts to long - and enemy is changing in turbine - not only 1 tpf


I can’t see your current code so I cannot comment on whether something else got messed up. I only know that modifying the results of “get” methods directly in JME is bad. If you want to set the rotation of something then set its rotation.

As to your actual problem, I bet if you added some System.out.println() that verify your assumptions then you would see the issue immediately.


I appreciate it. Then allright . So what is the fastest and most efficient method to rotate of spatial model ( attached to physics) say in few lines?

       Vector3f dirToPlayer = characterNode.getWorldTranslation().subtract(enemyNode.getWorldTranslation()).normalizeLocal();    
       Vector3f enemyUp=characterNode.getLocalRotation().mult(Vector3f.UNIT_Y);  
       enemy.lookAt(dirToPlayer, enemyUp);

I did it basically as above. The problem is that enemy is tracing target negatively. I’m turning left but enemy is rotating right side. How to deal with it?


If you multiply something by -1 you invert it.


It is obvious. However I have a problem with finding what is “something” and how to extract eventual “something” from my code.


lookAt() takes a location… not a direction vector. It internally is already going to subtract the spatial position. (Making the assumption that ‘enemy’ is a spatial.)

Code and javadoc are always one click away. TREMENDOUSLY helpful in most cases.