Mouse click and animation

Hello,

I wanna do attack animations while clicking LPM. Here are codes:
[java] public void setUpKeys() {
inputManager.addMapping(“Hit”, new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
inputManager.addListener(this, “Hit”);
}

public void onAction(String binding, boolean isPressed, float tpf) {
} else if (binding.equals(“Hit”)) {
hit = isPressed;
currentAnim = getRandomAnim();
}

        } else if (hit) {
            if (channel.getAnimationName() == null) {
                channel.setAnim(currentAnim);
                channel.setLoopMode(LoopMode.DontLoop);
            }

        } else {
            channel.reset(true);
        }

[/java]

but in game I MUST Hold LPM to run animation to the end. Also when it’s done it doesn’t back to my stand animation. What I have to do to just simple click once LPM, animation is executing until it’s finished and player back to stand/reset animation?

Except the first part of the onAction that must not compile as is (I guess you removed some parts for this post), this code explicitely reset the channels when the button is released.
I guess you misunderstand whet the reset does, and there are very few reason why you should use it.
remove the else part with channel.reset(true).

What you describe as a desired behavior is exactly what is done in the HelloAnimation tutorial https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_animation
I strongly encourage you to go through all tutorials