enemyNode.lookAt(characterNode.getLocalTranslation(), Vector3f.UNIT_Y); // watching player
Quaternion rotateEnd = enemyNode.getLocalRotation(); // Final rotation;
if (tick < 1) {
rotateEnd.multLocal(enemyViewDirection);
tick += 1;
}
physicsCharacterEnemy.setViewDirection(enemyViewDirection);
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);
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 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?
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.