Hello, i'm trying to extend physics BallThrower to a more general form firing missiles of in the direction of a given spatial of which i hold a reference ( CameraNode or gun barrel …)
my shoot - method is as follows:
/**
* Shoots a missile in the direction of a Spatial (Gun).
*/
private void shoot() {
// Move to the next ball index.
missileIndex++;
if (missileIndex >= pMissiles.length) missileIndex = 0;
// Enable and show it in case it wasn't before.
pMissiles[missileIndex].setEnabled(true);
pMissiles[missileIndex].getSpatial().setForceCull(false);
// Set the missiles position and direction to the barrels
pMissiles[missileIndex].getSpatial().getLocalRotation().set(barrel.getLocalRotation());
pMissiles[missileIndex].getSpatial().getLocalTranslation().set(barrel.getLocalTranslation());
pMissiles[missileIndex].getSpatial().updateGeometricState(-1f, true);
pMissiles[missileIndex].syncWithGraphical();
pMissiles[missileIndex].resetForces();
// Shoot it in the direction of the camera with the selected force.
pMissiles[missileIndex].addForce(barrel.getLocalRotation().getRotationColumn(2).mult(shootForce, forceVec));
// Reset the timer.
elapsedTime = 0;
}
my problem with this is that the missile does not point in the direction i face but in the direction i started of (default CameraNode orientation)
so if i fire the first msl it works as expected, but when turning my camNode and firing the next it points in the direction the first did.
if i change the line setting the rotation to:
pMissiles[missileIndex].getSpatial().setLocalRotation(barrel.getLocalRotation());
then the shootoff works but as the missiles Quaternion is a reference to the CamNodes ... the missile turns as i turn the camNode.
I think the first method should work but am stuck finding out why it doesn't, what do i miss here ???