I have been trying to use a reworked version of flagrush lession 9 as a sample to start playing with jME. I have replaced the bike with a model of a tank which has a child node turret (Set in blender as the whole tank is one model). I have loaded it in as a jme xml file no problem
I can even rotate the turret in the direction of the camera BUT… if I turn the tank the turret moves also and no longer points in the same direction as the camera (using chase camera if that makes a difference)
In the update method of Lession9 I have added the line
public void updateTurret(Vector3f camLoc,Vector3f camDirection){
Vector3f v = new Vector3f(
model.getWorldTranslation().x,
model.getWorldTranslation().y,
model.getWorldTranslation().z );
v.addLocal( camDirection.x, 0f ,camDirection.z );
Turret.lookAt( v , Vector3f.UNIT_Y );
}
I was under the impression that it should just pull the details off the camera and still set the turret in the correct direction even though the tank has rotated
It sounds to me like an issue of world vs local coordinates. I'm not sure about your scenegraph, but you can try using:
model.getLocalTranslation()
I'm not convinced that will fix this, however. From what you said, I think you want to move the tank and keep the turret pointing in the same position. If that is the case, than the easiest thing to do would be to 'save' the position of the turret before you start moving both the camera and the rest of the tank.
Example:
// rest of your class above
private Vector3f turretDirection;
public void turnTurret(Vector3f camDirection){
turretDirection=camDirection;
Turrent.lookAt(turretDirection, Vector3f.UNIT_Y);
}
What you want to do is update the turret to the 'saved' location every time you turn the tank itself. What's happening in your scene is that the tank is turning, which in turn makes the turret turn as well since the turret is attached to the tank.
In other words, your scene graph looks like this:
Tank
|_Turret
Moving the parent moves the child, same for rotations.
Try putting a cube off to the side of the scene and have the turret look at it on every update. The desired functionality would be that you drive the tank around and the turret automatically 'aims' itself at this cube.
This really depends on how things are attached in your scene. It sounds like your manipulating the model too high in the hierarchy. Can you confirm how the various Nodes, TriMesh's, etc are structured? There's a big difference in whether the turret is attached directly to the rest of the tank or to a Node that directly parents them both
unfortunatley it doesn't really point in the right direction either, which I guess means Im doing it wrong or something isnt set right.
If I can get it to point to an object that would be better then I can attach the chase camera to the turret which may then look in the right direction, I will just then need to move the box with the mouse