Animation in twitching in HelloAnimation, what happening?

Hello all,



I’m going through the tutorials and I’m currently at HelloAnimation.



I added some new animations triggered by input and I’m getting a twitch when I dodge (key down).

Can anybody explain what is going on?



Here is the code:



[java]package jme3test.helloworld;



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.DirectionalLight;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.scene.Node;



/** Sample 7 - how to load an OgreXML model and play an animation,

  • using channels, a controller, and an AnimEventListener. /

    public class HelloAnimation extends SimpleApplication

    implements AnimEventListener {

    private enum ActionNames{

    PULL (“pull”), PUSH (“push”), WALK (“Walk”), DODGE(“Dodge”);

    public String name;



    private ActionNames(String name){

    this.name = name;

    }

    }

    private AnimChannel channel;

    private AnimControl control;

    Node player;

    public static void main(String[] args) {

    HelloAnimation app = new HelloAnimation();

    app.start();

    }



    @Override

    public void simpleInitApp() {

    viewPort.setBackgroundColor(ColorRGBA.LightGray);

    initKeys();

    DirectionalLight dl = new DirectionalLight();

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

    rootNode.addLight(dl);

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

    player.setLocalScale(0.5f);

    rootNode.attachChild(player);

    control = player.getControl(AnimControl.class);

    control.addListener(this);

    channel = control.createChannel();

    channel.setAnim(“stand”);

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

    }



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

    if (animName.equals(ActionNames.WALK.name)||animName.equals(ActionNames.PUSH.name)||animName.equals(ActionNames.PULL.name)||animName.equals(ActionNames.DODGE.name)) {

    channel.setAnim(“stand”, 0.50f);

    channel.setLoopMode(LoopMode.DontLoop);

    channel.setSpeed(1f);

    }

    }



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

    // unused

    }



    /
    * Custom Keybinding: Map named actions to inputs. */

    private void initKeys() {

    inputManager.addMapping(ActionNames.WALK.name, new KeyTrigger(KeyInput.KEY_SPACE));

    inputManager.addMapping(ActionNames.PUSH.name, new KeyTrigger(KeyInput.KEY_RIGHT));

    inputManager.addMapping(ActionNames.PULL.name, new KeyTrigger(KeyInput.KEY_LEFT));

    inputManager.addMapping(ActionNames.DODGE.name, new KeyTrigger(KeyInput.KEY_DOWN));

    inputManager.addListener(actionListener, new String[]{ActionNames.WALK.name,

    ActionNames.PUSH.name, ActionNames.PULL.name, ActionNames.DODGE.name});

    }

    private ActionListener actionListener = new ActionListener() {

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

    if (name.equals(ActionNames.WALK.name) && !keyPressed) {

    if (!channel.getAnimationName().equals(ActionNames.WALK.name)) {

    channel.setAnim(ActionNames.WALK.name, 0.50f);

    channel.setLoopMode(LoopMode.Loop);

    }

    } else if (name.equals(ActionNames.PUSH.name) && !keyPressed) {

    System.out.println(“push”);

    if (!channel.getAnimationName().equals(ActionNames.PUSH.name)) {

    channel.setAnim(ActionNames.PUSH.name, 0.50f);

    channel.setLoopMode(LoopMode.Loop);

    }

    } else if (name.equals(ActionNames.PULL.name) && !keyPressed) {

    System.out.println(“pull”);

    if (!channel.getAnimationName().equals(ActionNames.PULL.name)) {

    channel.setAnim(ActionNames.PULL.name, 0.50f);

    channel.setLoopMode(LoopMode.Loop);

    }

    } else if (name.equals(ActionNames.DODGE.name) && !keyPressed) {

    if (!channel.getAnimationName().equals(ActionNames.DODGE.name)) {

    channel.setAnim(ActionNames.DODGE.name, 0.50f);

    channel.setLoopMode(LoopMode.Cycle);

    channel.setSpeed(0.4f);

    }

    }

    }

    };

    }



    [/java]



    P.S.: I wasn’t able to google because I don’t know what to call it.
1 Like

Thanks, the bugs were fixed