Hi everyone!
I am trying to add an animation to a Node. The animation simply changes the rotation of the node over time. (The node is used to control a weapon, like a turret).
My problem is, everything works fine until you add the animation for the first time. At that point, the weapon node jumps from its correct position (0,6,0), to (0,0,0), seemingly without being told.
Further, when I am debugging it through the use of Print statements, the Node is printed out as “null (Node)”, But I am confident it is not null, and no exceptions are raised.
I really have no clue what is happening! I’m sure it shouldn’t be null, as there are methods being applied to this ‘null’ Node, and I really don’t see why it would change location regardless. Any help would be appreciated!
An excerpt from the Print-out is shown below, starting from the first instance where the animation is applied
RECEIVED: $$WEAPROT:1|192.168.1.8|8889|-0.18309613, 0.6810445, 0.18292011, 0.68497765|1 Shooting! Player null (Node) Node location: (0.0, 6.0, 0.0) Player TurbineCannon-geom-0 (Geometry) location: (0.0, 1.0, 0.0) Shooting = true Shooting value = 1 New Player null (Node) Node location: (0.0, 0.0, 0.0) New Player TurbineCannon-geom-0 (Geometry) location: (0.0, 1.0, 0.0) RECEIVED: $$WEAPROT:1|192.168.1.8|8889|-0.18301918, 0.6813391, 0.18299787, 0.68468446|1 Shooting! Player null (Node) Node location: (0.0, 0.0, 0.0) Player TurbineCannon-geom-0 (Geometry) location: (0.0, 1.0, 0.0) Shooting = true Shooting value = 1 New Player null (Node) Node location: (0.0, 0.0, 0.0) New Player TurbineCannon-geom-0 (Geometry) location: (0.0, 1.0, 0.0) RECEIVED: $$WEAPROT:1|192.168.1.8|8889|-0.18295474, 0.68163043, 0.18306322, 0.6843941|1 Shooting! Player null (Node) Node location: (0.0, 0.0, 0.0) Player TurbineCannon-geom-0 (Geometry) location: (0.0, 1.0, 0.0) Shooting = true Shooting value = 1 New Player null (Node) Node location: (0.0, 0.0, 0.0) New Player TurbineCannon-geom-0 (Geometry) location: (0.0, 1.0, 0.0)
The code controlling the animation is here:
public void updatePeerWeapon(Quaternion weapRot, Boolean shooting, float delay)
{
final Quaternion newWeapRot = weapRot;
Quaternion curWeapRot = playerVehicle.getPlayerWeaponNode().getLocalRotation();
System.out.println("Player "+ playerVehicle.getPlayerWeaponNode()+" Node location: "+playerVehicle.getPlayerWeaponNode().getLocalTranslation());
System.out.println("Player "+ playerVehicle.getPlayerWeapon().getWeapon().toString() +" location: "+playerVehicle.getPlayerWeapon().getWeapon().getLocalTranslation());
if(shooting == true){playerVehicle.startShooting();}else{playerVehicle.stopShooting();}
AnimationFactory factory = new AnimationFactory(delay, "weapRot");
factory.addTimeRotation(0, curWeapRot);
factory.addTimeRotation(delay, newWeapRot);
final AnimControl rotAnimControl = new AnimControl();
rotAnimControl.addAnim(factory.buildAnimation());
playerVehicle.getPlayerWeaponNode().addControl(rotAnimControl);
rotAnimControl.createChannel().setAnim("weapRot");
rotAnimControl.getChannel(0).setLoopMode(LoopMode.DontLoop);
rotAnimControl.addListener(new AnimEventListener(){
public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {
playerVehicle.getPlayerWeaponNode().removeControl(rotAnimControl);
playerVehicle.getPlayerWeaponNode().setLocalRotation(newWeapRot);
System.out.println("New Player "+ playerVehicle.getPlayerWeaponNode() +" Node location: "+playerVehicle.getPlayerWeaponNode().getLocalTranslation());
System.out.println("New Player "+ playerVehicle.getPlayerWeapon().getWeapon().toString() +" location: "+playerVehicle.getPlayerWeapon().getWeapon().getLocalTranslation());
//playerVehicle.setShooting(false);
}
public void onAnimChange(AnimControl control, AnimChannel channel, String animName) {
}
});
}