Player animations

Hello.

I was doing quick-animations few days ago just only for “working” but now need to rebuild that. I got animations for different Keys and mouse click but I need to set up standing/idle animation (randomly chosed by java). Here’s the code, I want currentStandAnim to be played like .reset work already. (when i stop pressing any key now my animations are reset.) but with possibility to stop it in any time when player press the key, even when idle anim isn’t finished.
[java] currentStandAnim = getRandomStand();

    Node rigNode = (Node) playerModel.getChild("rig");
    for (Spatial sp : rigNode.getChildren()) {

        AnimControl animCtrl = sp.getControl(AnimControl.class);
        if (animCtrl.getNumChannels() == 0) {
            animCtrl.createChannel();
        }
        AnimChannel channel = animCtrl.getChannel(0);            

         if (up || down || right || left && isDefending == false) {
            if (channel.getAnimationName() == null) {
                if (isAccelerate == false) {
                channel.setAnim(anim10, 1f);
                } else {
                channel.setAnim(anim11, 1f);
                }
                channel.setLoopMode(LoopMode.Loop);
            }

        } else if (hit && isDefending == false) {
            if (channel.getAnimationName() == null) {
                channel.setAnim(currentAnim);
                channel.setLoopMode(LoopMode.DontLoop);
            }
        } else if (isDefending) {
            if (channel.getAnimationName() == null) {
                channel.setAnim(currentDefAnim);
                channel.setLoopMode(LoopMode.DontLoop);
        }
          } else {
           channel.reset(true);
        }[/java]

You could check the current animation name if it is not null against your idle anim name?

What exactly do u mean? To check animation name while its playing?

@Skatty said: What exactly do u mean? To check animation name while its playing?
channel.getAnimationName() returns the name of the currently playing animation

So any ideas? :frowning:

Tried smth like: [java]if (up && down && right && left && isDefending && hit == false) {
if (channel.getAnimationName() == null) {
channel.setAnim(currentStandAnim);
channel.setLoopMode(LoopMode.DontLoop);
}
…[/java]

but now my char is all the time playing stand anim

I read again your first post and for me that’s the typical use case of the HelloAnimation tutorial https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_animation

Either I didn’t get what you want to achieve either you didn’t read it.

I just want set stand anim when i’m not pressing anything. now its default humanoid pose - each anim is reset/stopped after i stop pressing smth.

this is what you want to do

[java]if (channel.getAnimationName() == null || !channel.getAnimationName().equals(currentStandAnim)) {
channel.setAnim(currentStandAnim);
channel.setLoopMode(LoopMode.DontLoop);
}[/java]

as you add more animations and more features your code to manage the animation state of your model will get more complicated.

I added:
} else if (channel.getAnimationName() == null) {
channel.setAnim(currentStandAnim);
channel.setLoopMode(LoopMode.DontLoop);

        }

and it work but not in 100%. It doesnt play animation to end but with each frame reset it to start and it looks weir lol.