I’m trying to create animation for my player. It has few meshes (like helmet, body, shield etc.) and each mesh got it own animation. I wanna collect them all and use as a 1 animation : Walk.
I’m getting error: NullPointerException when trying to add Listener to channel.
Here’s tree of my model and code below:
[java]
player = (Node) assetManager.loadModel(“Models/Test/krzyzak6.j3o”);
player.setLocalScale(2.5f);
rootNode.attachChild(player);
/** Create a controller and channels. */
control = player.getControl(AnimControl.class);
control.addListener(this);
channel = control.createChannel();
channel.addAllBones();
channel.setAnim("Walk");
}
public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {
if (animName.equals(“Walk”)) {
channel.setAnim(“Walk”, 0.50f);
channel.setLoopMode(LoopMode.valueOf(“Walk”));
channel.setSpeed(3f);
}
}
public void onAnimChange(AnimControl control, AnimChannel channel, String animName) {
// unused
}
/** Custom Keybinding: Map named actions to inputs. */
private void initKeys() {
inputManager.addMapping(“Walk”, new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addListener(actionListener, “Walk”);
}
private ActionListener actionListener = new ActionListener() {
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals(“Walk”) && !keyPressed) {
if (!channel.getAnimationName().equals(“Walk”)) {
channel.setAnim(“Walk”, 0.50f);
channel.setLoopMode(LoopMode.Loop);
}
}
}
};
}[/java]