Wrong Animation is played

Hey all,

I have a very weird problem.

I just implemented a very basic animationController to load animations from my model and play them.

The problem is that my program runs the wrong animation.

These are my available Animations:
WALK_FORWARD,
WALK_BACKWARD,
COLLISION_WITH_WALL_FORWARD,
COLLISION_WITH_WALL_BACKWARD,
COLLISION_WITH_WALL_RIGHT,
COLLISION_WITH_WALL_LEFT,
CHECKPOINT_REACHED,
SPAWN_LAST_CHECKPOINT,
PUSHED_FORWARD,
PUSHED_BACKWARD,
PUSHED_RIGHT,
PUSHED_LEFT,
TURN_RIGHT,
TURN_LEFT,
WALK_AND_PUSH_FORWARD,
WALK_AND_PUSH_BACKWARD,
WAIT,
FALL_DOWN,
DESTROY,
WIN,
DISQUALIFY,
DEAD

And It always play the COLLISION_WITH_WALL_LEFT . Code is below, thanks for your help in advance :slight_smile:

public class AnimController {

AnimControl animcontrol;
AnimChannel channel;
Spatial model;


public AnimController(Spatial spa){
    this.model = spa;
    animcontrol = spa.getControl(AnimControl.class);
    animcontrol.clearChannels();
    channel = animcontrol.createChannel();
    channel.setAnim("WAIT");
   
    
}

public float getAnimLength(AnimState animState){
    channel.setAnim("WAIT");
    return animcontrol.getAnimationLength(animState.toString());
}

}

public void simpleUpdate(float tpf) {
    if(counter > animlength){
        counter = 0;
        if(!animList.isEmpty()){
            
            animlength = animController.getAnimLength(animList.get(0));
            System.out.println("Set new animation: " + animList.get(0).toString());
            animList.remove(0);
            
        }else{
            for(AnimState animstate : AnimState.values()){
                animList.add(animstate);
            }
        }
    }else{
        counter += tpf;
    }
}

Spatial model = assetManager.loadModel(“Models/DrivingOven.mesh.j3o”);
TangentBinormalGenerator.generate(model);

    Material matQuad = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    
    Texture difTex = assetManager.loadTexture("Textures/T_DrivingOven_albedo.png");
    difTex.setWrap(Texture.WrapMode.Repeat);
    matQuad.setTexture("DiffuseMap", difTex);

    Texture normalTex = assetManager.loadTexture("Textures/old_T_DrivingOven_normal.png");
    normalTex.setWrap(Texture.WrapMode.Repeat);
    matQuad.setTexture("NormalMap", normalTex);

    Texture specularTex = assetManager.loadTexture("Textures/T_DrivingOven_specular.png");
    matQuad.setTexture("SpecularMap" , specularTex);
    
    matQuad.setBoolean("UseMaterialColors", false
            );
    matQuad.setColor("Ambient", ColorRGBA.White);
    matQuad.setColor("Diffuse", ColorRGBA.White);  // minimum material color
    matQuad.setColor("Specular", ColorRGBA.White); // for shininess
    matQuad.setFloat("Shininess", 64f); // [1,128] for shininess
    
    matQuad.setReceivesShadows(true);
    model.setShadowMode(ShadowMode.CastAndReceive);
    
    model.setMaterial(matQuad);
    
    animController = new AnimController(model);
    
    rootNode.attachChild(model);
1 Like

Your code is a little weird though…

What is your goal? (I assume you want to play animation after animation and when you reached the end you want to start from the beginning again, right?)

EDIT:
Also have a look at the tutorials!
https://jmonkeyengine.github.io/wiki/jme3/beginner/hello_animation.html#animation-controller-and-channel

1 Like

Yeah thats my goal (so that I can check each animation)

My code is build based on this tutorial but I cannot see my mistake

1 Like

All the animations are also available

Output from for (String anim : animcontrol.getAnimationNames()) {
System.out.println("Anim: " + anim);
}

Anim: DESTROY
Anim: FALL_DOWN
Anim: COLLISION_WITH_WALL_RIGHT
Anim: COLLISION_WITH_WALL_BACKWARD
Anim: PUSHED_FORWARD
Anim: WIN
Anim: DISQUALIFY
Anim: TURN_RIGHT
Anim: PUSHED_RIGHT
Anim: WAIT
Anim: ArmatureAction
Anim: WALK_FORWARD
Anim: WALK_BACKWARD
Anim: COLLISION_WITH_WALL_FORWARD
Anim: CHECKPOINT_REACHED
Anim: SPAWN_LAST_CHECKPOINT
Anim: COLLISION_WITH_WALL_LEFT
Anim: DEAD
Anim: WALK_AND_PUSH_BACKWARD
Anim: WALK_AND_PUSH_FORWARD
Anim: PUSHED_BACKWARD
Anim: ArmatureAction.001
Anim: Wait.001
Anim: TURN_LEFT
Anim: PUSHED_LEFT

1 Like

You arent setting the new Animation and even then, getAnimLength sets the anim to WAIT.

Try to debug your Code Step by Step.
Btw you can also Test the Animations in the sdks scenecomposer

1 Like

The problem is that I want the WAIT animation to run but it never do, thats why I hardcoded in there.

How does the test with the scenecomposer works?

1 Like

https://jmonkeyengine.github.io/wiki/sdk.html
Specifically
https://jmonkeyengine.github.io/wiki/sdk/scene_composer.html#loading-the-scene

Once you open the spatial, you can navigate to the animcontrol and play them.

1 Like

The animations are completly broken in the scene composer, I have to investigate my export process

thanks for all your help :slight_smile:

1 Like