Two Animations

I was exploring animations and was trying to make my model play two animations at once. However, in the tutorial, it doesn’t say explicitly how to do that. I was trying the following:



[java]

control = Main.player.getControl(AnimControl.class);

control.addListener(this);

channel = control.createChannel();

channel2 = control.createChannel();

channel.setAnim(“1”);

channel2.setAnim(“2”);

[/java]

^Set a default animation and initialize the control and channels.



Then, when the user presses LMB, the following code is executed:



[java]

Mchannel2.setAnim(“2”);

Mchannel2.setLoopMode(LoopMode.Cycle);

Mchannel.setAnim(“1”);

Mchannel.setLoopMode(LoopMode.Cycle);

[/java]

^Where Mchannel is channel from the other class, and Mchannel2 is channel2 from the other class.



However, when it works, Animation “1” doesn’t work well. If it should rotate the leg by 90 degrees, it rotates 5 or less. What am I doing wrong?

aren’t you supposed to “switch-off” the bones that are not to be affected by a given channel…I could be wrong though

1 Like

How do I switch them off? I only found: Mchannel2.addAllBones(); in the Advanced Animation Tut

Yeah mcbeth is right,

look at this tutorial

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:animation



if two animations own the same bone, they’ll will both be telling it what to do, and you will get strange results



EDIT Oh it looks like you already found it… i believe adding bones is fine, i believe it will remove the ones assigned by default (which is all of them) if you do



LOOK in the test case code



[java]

AnimChannel feet = control.createChannel();

AnimChannel leftHand = control.createChannel();

AnimChannel rightHand = control.createChannel();



// feet will dodge

feet.addFromRootBone(“hip.right”);

feet.addFromRootBone(“hip.left”);

feet.setAnim(“Dodge”);

feet.setSpeed(2);

feet.setLoopMode(LoopMode.Cycle);

[/java]

1 Like

Thanks a lot :slight_smile: I didn’t notice there were test cases. I added the bones which were needed and it worked well.