I tried that code and it helped centering the projectile to the players center, but the projectiles were all facing/shooting towards -X.
So I added "bullet[n].setRotationPivot(player.getZAxis())" to fix that, but the projectile is still offset depending on the YAxis of the player. (Same as before)
If I point the player towards:
+Y = OK
-Y = OK
+Z = OK
-Z = OK
+X = The projectiles are slightly offset to the left of the object
-X = The projectiles are slightly offset to the right of the object
Current code:
bullet[n].clearTranslation();
bullet[n].translate(player.getTransformedCenter()); // getTranslation doesn't work properly
bullet[n].getRotationMatrix().setTo(player.getRotationMatrix());
bullet[n].setRotationPivot(player.getZAxis()); // Added because the projectiles were pointing towards -X
//bullet[n].setRotationPivot(player.getRotationPivot()); // No good. All projectiles point to -Z
I am rotating the player per frame using just rotateAxis which is working well. (not using Object3D.rotateY etc..)
// Horz
player.rotateAxis(player.getYAxis(), (fSenseYaw*0.1f)*fDiv);
// Vert
player.rotateAxis(player.getXAxis(), (fSensePitch*0.1f)*fDiv);
I am moving the projectile per frame using:
// Move in its direction
SimpleVector sv = bullet[n].getRotationPivot(); //sv = bullet[n].getZAxis(); (getZ doesnt work properly)
sv.scalarMul(10.0f);
bullet[n].translate(sv);
Thinking the object was off center, I tried correcting it by translating the mesh (Z ways) and then calling translateMesh() but that didn't help. The object itself became way off the camera's center depending on the Rotational Axis.
I also tried replacing the object with a simple cube primitive (loading it with just two lines of code), with no pre translation or rotation:
player = Primitives.getCube(1);
world.addObject(player);
But the projectiles are still offset when point towards -X or +X
I can't figure out why that is happening. I guess I could correct it on the fly by translating Z depending on the XAxis.x value, but I would like to avoid that kind of correction if possible.