Hi guys, I’m trying to do some simple animations in JMonkey with the Oto model but although all of the keys I added show some results, some of them are not quite expected. For example the Walk and the Dodge command seem to show different result. If I only add one command at a time for Walk and Dodge, then the effect is changed! However for push and pull, the effects are unchanged. I’m quite confounded and I’ll be posting my code here. Any help will be appreciated. Thanks a lot
package mygame;
import com.jme3.animation.AnimChannel;
import com.jme3.animation.AnimControl;
import com.jme3.animation.AnimEventListener;
import com.jme3.animation.LoopMode;
import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
public class HelloAnimation extends SimpleApplication implements AnimEventListener{
Node player;
private AnimControl control;
private AnimChannel[] channel = new AnimChannel[4];
private String[] str = {“Dodge”, “Walk”, “push”, “pull”};
public static void main(String[] args){
HelloAnimation app = new HelloAnimation();
app.start();
}
@Override
public void simpleInitApp(){
flyCam.setMoveSpeed(10);
viewPort.setBackgroundColor(ColorRGBA.LightGray);
AddLight();
initKeys();
player = (Node) assetManager.loadModel(“Models/Oto/Oto.mesh.xml”);
player.setLocalScale(0.5f);
rootNode.attachChild(player);
control = player.getControl(AnimControl.class);
control.addListener(this);
for (int i = 0; i < 4; i++){
channel = control.createChannel();
channel.setAnim(“stand”);
}
}
public void AddLight(){
AmbientLight al = new AmbientLight();
al.setColor(ColorRGBA.White.mult(1.3f));
rootNode.addLight(al);
DirectionalLight sun = new DirectionalLight();
sun.setColor(ColorRGBA.White);
sun.setDirection(new Vector3f(2.8f, -2.8f, -2.8f).normalizeLocal());
rootNode.addLight(sun);
}
public void initKeys(){
inputManager.addMapping(“pull”, new KeyTrigger(KeyInput.KEY_J));
inputManager.addMapping(“push”, new KeyTrigger(KeyInput.KEY_L));
inputManager.addMapping(“Walk”, new KeyTrigger(KeyInput.KEY_I));
inputManager.addMapping(“Dodge”, new KeyTrigger(KeyInput.KEY_K));
inputManager.addListener(ac, “pull”);
inputManager.addListener(ac, “push”);
inputManager.addListener(ac, “Walk”);
inputManager.addListener(ac, “Dodge”);
}
private ActionListener ac = new ActionListener(){
public void onAction(String name, boolean keyPressed, float tpf){
if ((name.equals(“stand”) == false) && !keyPressed){
int i = 0;
for (i = 0; i < 4; i++){
if (name.equals(str) == true) break;
}
if (!channel.getAnimationName().equals(str)) {
channel.setAnim(str, 0.50f);
channel.setLoopMode(LoopMode.Loop);
}
}
}
};
public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName){
if (animName.equals(“stand”) == false){
channel.setAnim(“stand”, 0.50f);
channel.setSpeed(1.00f);
channel.setLoopMode(LoopMode.DontLoop);
}
}
public void onAnimChange(AnimControl control, AnimChannel channel, String animName){
}
}