playMaker

Author Topic: How to play random animations with Mecanim  (Read 15170 times)

Sheridah

  • Playmaker Newbie
  • *
  • Posts: 14
How to play random animations with Mecanim
« on: July 25, 2013, 04:33:08 AM »
Hi everybody,

just a quick question:
I want my character to have multiple idle animations that play in random order. To me the fastest way to do that seemed to create a blendtree with the idle animations that uses a parameter Idle to choose between the animations.

I'v tried this with "Random Float" & "Set Animator Float" but it only picks a number once and then sticks with it.

All the other solutions on this site are for the old animation system and thus not very helpful.

Any tips?

Many thanks!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to play random animations with Mecanim
« Reply #1 on: July 29, 2013, 06:04:02 AM »
Hi,

 you are on the right path it seems:

http://forum.unity3d.com/threads/152489-Mecanim-Play-Random-Animations-in-Idle-State

Random Float needs to be trigger again if you want a new random pick, so leave and enter the state again to have a new random float.

bye,

 Jean

Sheridah

  • Playmaker Newbie
  • *
  • Posts: 14
Re: How to play random animations with Mecanim
« Reply #2 on: August 03, 2013, 02:55:07 AM »
Hey Jean,

Thank you for your reply. I've tried your suggestion by re-entering the state after sending the float to the animator but I end up with an infinite loop. Which of course make complete sense.

My question is if it's possible to receive a message from the animator when the animation is finished that can be used as trigger for the random float?

Thank you in advance :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to play random animations with Mecanim
« Reply #3 on: August 05, 2013, 04:08:40 AM »
Hi,
 
 currently, If you look at the demos provided for PlayMaker and Mecanim, you'll see that you don't really get events back from mecanim, but instead you watch for the current state and take decision based on that.


so typically you use the action "GetAnimatorCurrentStateInfoIsName"

https://hutonggames.fogbugz.com/default.asp?W1031

you can see an example in "TargetWatch" on the character, fsm "Target match", state "Can we match?"

Study all this carefully. don't hesitate to ask question on features and design pattern that doesn't make sense or give you trouble.

bye,

Jean

tankun

  • Playmaker Newbie
  • *
  • Posts: 26
Re: How to play random animations with Mecanim
« Reply #4 on: August 13, 2013, 02:19:36 AM »
Hi Jean,

In the Target Match example, the syntax for the get animator current state info is name action is: "Base Layer.JumpUp".

This syntax doesn't work if the action "JumpUp" is in a Sub-State Machine.

Supposing the name of the Sub-State Machine is "Jumping"; what would be the correct syntax would be?

I tried something like "Base Layer.Jumping.JumpUp" but didn't work.

Thanks,

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to play random animations with Mecanim
« Reply #5 on: August 14, 2013, 03:54:44 AM »
Hi,

 Have you tried "Jumping.JumpUp". Also you should ask this in Unity forum and unityQA, I think you will have a better chance to get a proper advice on this.

Keep us updated.

bye,

Jean

Sheridah

  • Playmaker Newbie
  • *
  • Posts: 14
Re: How to play random animations with Mecanim
« Reply #6 on: August 19, 2013, 07:22:25 PM »
I've checked out the Target match project but I can't get the target match to work in my own projects. For some reason it moves the root towards the target instead of the set bodypart. What am I doing wrong?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to play random animations with Mecanim
« Reply #7 on: August 20, 2013, 03:01:57 AM »
Hi,

 Are you properly masking and defining what part of the animation to play? you may simply play the whole anim.

In the sample, check all the things that happens when Fsm starts. A lot of set up is done for the masking to happen properly.

Bye,

Jean