Problem with animations

I have this code:





// package import



public class HelloAnimation extends SimpleApplication implements AnimEventListener {



private AnimChannel channel;

private AnimChannel channel2;

private AnimControl control;

Node player;



/* INPUT /

private final String INPUT_WALK_FORWARD = “walkForward”;

private final String INPUT_ATTACK1 = “attack1”;



/
ANIMAZIONI /

private final String ANIM_WALK = “Walk”;

private final String ANIM_IDLE1 = “Idle1”;

private final String ANIM_ATTACK1 = “Attack1”;



/
ACTION LISTENER /

private ActionListener actionListener = new ActionListener() {

public void onAction(String name, boolean keyPressed, float tpf) {

if (name.equals(INPUT_WALK_FORWARD) && !keyPressed) {

channel.setAnim(ANIM_IDLE1);

channel.setLoopMode(LoopMode.Loop);

}

if (name.equals(INPUT_ATTACK1) && !keyPressed) {

channel2.setAnim(ANIM_ATTACK1);

channel2.setLoopMode(LoopMode.DontLoop);

}

}

};



/
ANALOG LISTENER /

private AnalogListener analogListener = new AnalogListener() {

public void onAnalog(String name, float value, float tpf) {

if (name.equals(INPUT_WALK_FORWARD)) {

System.out.println(channel.getAnimationName());

if (!channel.getAnimationName().equals(ANIM_WALK)) {

channel.setAnim(ANIM_WALK, 0.50f);

channel.setLoopMode(LoopMode.Loop);

}

Vector3f v = player.getLocalTranslation();

player.setLocalTranslation(v.x, v.y, v.z + value
speed*5);

}

}

};



public static void main(String[] args) {

HelloAnimation app = new HelloAnimation();

app.start();

}



@Override

public void simpleInitApp() {



flyCam.setMoveSpeed(10f);



viewPort.setBackgroundColor(ColorRGBA.LightGray);

initKeys();



Spatial gameLevel = assetManager.loadModel(“Scenes/town/main.j3o”);

gameLevel.setLocalTranslation(0, -5.2f, 0);

gameLevel.setLocalScale(2);

rootNode.attachChild(gameLevel);



DirectionalLight dl = new DirectionalLight();

dl.setDirection(new Vector3f(-0.1f, -1f, -1).normalizeLocal());

rootNode.addLight(dl);



player = (Node) assetManager.loadModel(“Models/Ninja/Ninja.mesh.xml”);

player.scale(0.05f, 0.05f, 0.05f);

player.rotate(0.0f, -3.0f, 0.0f);

player.setLocalTranslation(0.0f, -5.0f, -2.0f);

rootNode.attachChild(player);



control = player.getControl(AnimControl.class);

control.addListener(this);



for (String anim : control.getAnimationNames()) System.out.println(anim);



channel = control.createChannel();

channel2 = control.createChannel();



channel.setAnim(ANIM_IDLE1);



}



public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {

if (animName.equals(ANIM_WALK)) {

channel.setAnim(ANIM_IDLE1);

}

if (animName.equals(ANIM_ATTACK1)) {

channel.setAnim(ANIM_IDLE1);

}

}



public void onAnimChange(AnimControl control, AnimChannel channel, String animName) {}



private void initKeys() {

inputManager.addMapping(INPUT_WALK_FORWARD, new KeyTrigger(keyInput.KEY_U));

inputManager.addMapping(INPUT_ATTACK1, new KeyTrigger(keyInput.KEY_SPACE));



inputManager.addListener(analogListener, INPUT_WALK_FORWARD);



inputManager.addListener(actionListener, INPUT_WALK_FORWARD);

inputManager.addListener(actionListener, INPUT_ATTACK1);

}

}





I don’t understand why, if i do the attack1 (with SPACEBAR), when i try to walk forward, ninja doesn’t perform the Walk animation.



channel and channel2 are indipendent?

The channels independent but they require you to specify which bones of the model you’re influencing. Look in the TestOgreComplexAnim test on how to use channels properly.

So if two animations affect the same set of bones, it makes no sense to assign them to two different channels to simultaneously run, right?

Well what should the engine do? use the position from animation1 or from animation2?

Seems like you need another animation for me or split and use them with the bones they really need

Ok. Suppose I have two animations like this:


  1. “Walk”, which involves the entire skeleton.
  2. “Attack1”, which involves the entire skeleton.



    Can you attack WHILE walking? The engine is capable of mixing two animations?



    I ask this because, for example, the C library Cal3d is able to do so.

Yes thats possible

you have to specify wich bones the animations mody so the engine is able to do this however.