playMaker

Author Topic: Mecanim Follow Action  (Read 13414 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15552
  • Official Playmaker Support
Mecanim Follow Action
« on: November 21, 2012, 01:43:32 PM »
------- [UPDATE]
Mecanim packages shoudl now be downloaded here:
https://hutonggames.fogbugz.com/default.asp?W1031
-------

Hi Everyone,

 Ok, If you don't have Unity 4, get it now :)

The package attached to this thread is the beginning of PlayMaker support to Mecanim ( until it's officially supported of course)

You will need to import the "Mecanim Example Scenes" from the asset store.

Then you can import this package, and launch the scene

You'll notice that there is a PlayMakerMecanimProxy component. this simply allows PlayMaker Mecanim Actions to work properly as new monoBehavior methods exists to support Mecanim.

 I need to now create more granular actions for you to create your own behaviors and control Mecanim variables, but I am facing difficulties for this new monoBehavior methods I mentionned above, so need some more thinking :)

 So currently, specifically targeting a pending thread on that matter, you can have your avatar follow a target GameObject. This is good for ennemies, and also good for moving your avatar by touching the destination point, simply have the gameObject target getting dragged by the touch ( plenty of threads on that) and your avatar will nicely go there.


bye,

 Jean
« Last Edit: May 10, 2013, 03:58:14 AM by jeanfabre »

Dev_Sebas

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 398
    • Blog
Re: Mecanim Follow Action
« Reply #1 on: November 22, 2012, 11:42:55 AM »
Good news Jean!! :)
Thank you so much.
Keep it going.Please
Cheers
 

mickman

  • Junior Playmaker
  • **
  • Posts: 62
Re: Mecanim Follow Action
« Reply #2 on: November 22, 2012, 11:50:52 AM »
yup .. this will be amazing !!!   ;D

Playmaker + MoCap   =  PlayMo  or is it PlayMoc ??   whatever .. just super stoked to integrate PlayMaker with Mecanim.

 Nice One  Jean   :)

3d_Artist1987

  • Beta Group
  • Full Member
  • *
  • Posts: 157
Re: Mecanim Follow Action
« Reply #3 on: November 22, 2012, 11:05:44 PM »
hi,

thanks jean :)

Dev

play_edu

  • Full Member
  • ***
  • Posts: 116
Re: Mecanim Follow Action
« Reply #4 on: November 23, 2012, 12:00:34 AM »
Hi,


Thanks jean,


 it's Good news for us.


play_edu

Armada Animations

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Mecanim Follow Action
« Reply #5 on: November 28, 2012, 05:26:58 PM »
Hey Playmaker Users

I would have thought that Playmaker could always work with mecanim. Such as changing parameters through scripts. I quickly made some Playmaker actions as examples (they could obviously be improved).

e.g. for the bool I would do a reset when the animation has transitioned or even a change event.

Code: [Select]
using UnityEngine;
using HutongGames.PlayMaker;

[ActionCategory(ActionCategory.AnimateVariables)]
public class SetAnimatorFloatParameter : FsmStateAction
{
[RequiredField]
public FsmOwnerDefault gameObject;
public FsmFloat floatVariable;
public FsmString animatorParameter;
public bool everyFrame;

protected Animator animator;

// Code that runs on entering the state.
public override void OnEnter()
{
// get the animator component
var go = Fsm.GetOwnerDefaultTarget(gameObject);
animator = go.GetComponent<Animator>();

// Set the Float Parameter
if (animator)
SetParameter();

if (!everyFrame)
Finish();
}

// Code that runs every frame.
public override void OnUpdate()
{
if (animator)
SetParameter();
}

void SetParameter()
{
// Set the Animators Parameter
string para = animatorParameter.Value;
animator.SetFloat (para, floatVariable.Value) ;
}


}

Or changing a bool

Code: [Select]
using UnityEngine;
using HutongGames.PlayMaker;

[ActionCategory(ActionCategory.AnimateVariables)]
public class SetAnimatorBoolParameter : FsmStateAction
{
[RequiredField]
public FsmOwnerDefault gameObject;
public FsmBool boolVariable;
public FsmString animatorParameter;
public bool everyFrame;

protected Animator animator;

// Code that runs on entering the state.
public override void OnEnter()
{
// get the animator component
var go = Fsm.GetOwnerDefaultTarget(gameObject);
animator = go.GetComponent<Animator>();

// Set the Float Parameter
if (animator)
SetParameter();

if (!everyFrame)
Finish();
}

// Code that runs every frame.
public override void OnUpdate()
{
if (animator)
SetParameter();
}

void SetParameter()
{
// Set the Animators Parameter
string para = animatorParameter.Value;
animator.SetBool (para, boolVariable.Value) ;
}


}

3d_Artist1987

  • Beta Group
  • Full Member
  • *
  • Posts: 157
Re: Mecanim Follow Action
« Reply #6 on: November 29, 2012, 01:06:18 AM »
 :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15552
  • Official Playmaker Support
Re: Mecanim Follow Action
« Reply #7 on: December 11, 2012, 05:37:40 PM »
Hi,

 There you go!! thanks for your custom actions, much appreciated,

bye,

 Jean

Brighton

  • Playmaker Newbie
  • *
  • Posts: 9
Re: Mecanim Follow Action
« Reply #8 on: January 27, 2013, 11:41:00 PM »
Hey Armada,

These actions work great! Thank you for making them! :)

Preface: I'm an animator with a good technical understanding, but no scripting ability.

I have setup a fairly complex animation graph with many layers: Complex Locomotion, Aiming Overlays, Weapon actions, Hit Reactions, and life states.

My current problem is that Mecanim likes to set all extra animation layer weights to Zero at runtime (regardless of what is set in the controller).

I wanted to take your Mecanim Float action and alter the parameters to target the animation layer weights, but I can't find the correct documentation on that animation layer weight function.

Could someone help me out? Perhaps point me towards the correct documentation that specifies what the function for setting animation layer weights is?

Thanks again!

coldpizzapunk

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Mecanim Follow Action
« Reply #9 on: February 07, 2013, 12:00:16 AM »
I had the same question on weighting. I took the scripts above and found this line in another forum

Code: [Select]
animator.SetLayerWeight(1, 1);
I placed it here and it seems to work

Code: [Select]
void SetParameter()
{
// Set the Animators Parameter
string para = animatorParameter.Value;
animator.SetLayerWeight(1, 1);
animator.SetBool (para, boolVariable.Value) ;
}

I'm not really a programmer, more of a 3D visual guy. So while it works, I'm not sure if it's the right procedure. It would be cool to have it also have an input variable so you can set it in playmaker, rather than hardcoding it in. But I'm not sure how to do that.

coldpizzapunk

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Mecanim Follow Action
« Reply #10 on: February 07, 2013, 09:01:52 PM »
As a follow up I created an Int and Float input so in the menu you will see an input for which layer (Place the number of the layer you are setting the weight for) and you will have a slider to choose how much weight to give that layer.

Code: [Select]
using UnityEngine;
using HutongGames.PlayMaker;

[ActionCategory(ActionCategory.AnimateVariables)]
public class SetAnimatorBoolParameter : FsmStateAction
{
[RequiredField]
public FsmOwnerDefault gameObject;
public FsmBool boolVariable;
public FsmString animatorParameter;
[Tooltip("Which Layer To Apply To")]
public FsmInt layer;
[HasFloatSlider(0, 1)]
[Tooltip("Weight of Layer")]
public FsmFloat layerWeight;
public bool everyFrame;

protected Animator animator;

// Code that runs on entering the state.
public override void OnEnter()
{
// get the animator component
var go = Fsm.GetOwnerDefaultTarget(gameObject);
animator = go.GetComponent<Animator>();

// Set the Float Parameter
if (animator)
SetParameter();

if (!everyFrame)
Finish();
}

// Code that runs every frame.
public override void OnUpdate()
{
if (animator)
SetParameter();
}

void SetParameter()
{
// Set the Animators Parameter
string para = animatorParameter.Value;
animator.SetLayerWeight(layer.Value, layerWeight.Value);
animator.SetBool (para, boolVariable.Value) ;
}


}

Brighton

  • Playmaker Newbie
  • *
  • Posts: 9
Re: Mecanim Follow Action
« Reply #11 on: February 09, 2013, 03:35:32 AM »
Ah Very cool!

Thanks ColdPizzaPunk, I'll give this a shot. :)

FritsLyn

  • Full Member
  • ***
  • Posts: 191
Re: Mecanim Follow Action
« Reply #12 on: April 11, 2013, 04:58:53 PM »
you can have your avatar follow a target GameObject.

Can you explain *how*, please? (For a non programmer) thank you :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15552
  • Official Playmaker Support
Re: Mecanim Follow Action
« Reply #13 on: April 12, 2013, 02:13:37 AM »
Hi,

 Have you tested the package? the sample is about following a target. There is a custom action ( Animator Follow ) specifically written for this. you simply need to use that custom action.

Does that help?

bye,

 Jean