Animation shows very bad

I was creating a simple engine to show a character and play its animation. I tried it alone and the animation looks very bad. The character should make a kicking motion, but instead its leg gets stretched a lot. I even copied-pasted the code from the tutorial and the results were the same.



[java]

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

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.scene.Node;

import com.jme3.system.AppSettings;



public class Main extends SimpleApplication implements AnimEventListener{

private AnimChannel channel;

private AnimControl control;

Node player;

public static void main(String[] args) {

Main app = new Main();

app.setShowSettings(false);

AppSettings settings=new AppSettings(true);

settings.put("Width", 640);

settings.put("Height", 480);

settings.put("Title", "My Game");

settings.put("VSync", true);

settings.put("Samples", 4);

app.setSettings(settings);

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/Skele/Skele.j3o");

rootNode.attachChild(player);

control = player.getControl(AnimControl.class);

control.addListener(this);

channel = control.createChannel();

channel.setAnim("Stand");

}



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

if (animName.equals("Kick")) {

channel.setAnim("Stand", 0.50f);

channel.setLoopMode(LoopMode.DontLoop);

channel.setSpeed(1f);

}

}



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

// unused

}



private void initKeys() {

inputManager.addMapping("Kick", new KeyTrigger(KeyInput.KEY_SPACE));

inputManager.addListener(actionListener, "Kick");

}

private ActionListener actionListener = new ActionListener() {

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

if (name.equals("Kick") && !keyPressed) {

if (!channel.getAnimationName().equals("Kick")) {

channel.setAnim("Kick", 0.5f);

channel.setLoopMode(LoopMode.Loop);

}

}

}

};

}

[/java]



Any help please? Thanks in advance

Sounds like you exported the animation incorrectly. What format is the source model in?

Seems like it’s a small simple bug of OgreMax. Basically, you can’t export an animation with a symmetry modifier attached to it. I created a very simple half-stick man and used the symmetry modifier. Then, on top, I added the skin modifier. I deleted the skin modifier, and made the whole object as a polygon and then added the skin. Everything works fine now. Thanks.

@memonick said:
Seems like it's a small simple bug of OgreMax. Basically, you can't export an animation with a symmetry modifier attached to it. I created a very simple half-stick man and used the symmetry modifier. Then, on top, I added the skin modifier. I deleted the skin modifier, and made the whole object as a polygon and then added the skin. Everything works fine now. Thanks.

Yeah it's recommended to apply every modifiers to your objects before exporting (except the Armature modifier of course)

Had a hard time figuring that out. I started slashing parts of the stick man and the bones until I only had one leg left - and even when I exported its animation, it didn’t work well. I accidentally pressed CTRL+S instead of CTRL+Z and I had to do everything again :stuck_out_tongue: . Thankfully, I drew out the conclusion that the modifiers were the problem.