Playmaker Forum

PlayMaker News => General Discussion => Topic started by: jeanfabre on November 21, 2012, 01:43:32 PM

Title: Mecanim Follow Action
Post by: jeanfabre 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
Title: Re: Mecanim Follow Action
Post by: Dev_Sebas on November 22, 2012, 11:42:55 AM
Good news Jean!! :)
Thank you so much.
Keep it going.Please
Cheers
 
Title: Re: Mecanim Follow Action
Post by: mickman 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   :)
Title: Re: Mecanim Follow Action
Post by: 3d_Artist1987 on November 22, 2012, 11:05:44 PM
hi,

thanks jean :)

Dev
Title: Re: Mecanim Follow Action
Post by: play_edu on November 23, 2012, 12:00:34 AM
Hi,


Thanks jean,


 it's Good news for us.


play_edu
Title: Re: Mecanim Follow Action
Post by: Armada Animations 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) ;
}


}
Title: Re: Mecanim Follow Action
Post by: 3d_Artist1987 on November 29, 2012, 01:06:18 AM
 :)
Title: Re: Mecanim Follow Action
Post by: jeanfabre on December 11, 2012, 05:37:40 PM
Hi,

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

bye,

 Jean
Title: Re: Mecanim Follow Action
Post by: Brighton 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!
Title: Re: Mecanim Follow Action
Post by: coldpizzapunk 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.
Title: Re: Mecanim Follow Action
Post by: coldpizzapunk 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) ;
}


}
Title: Re: Mecanim Follow Action
Post by: Brighton on February 09, 2013, 03:35:32 AM
Ah Very cool!

Thanks ColdPizzaPunk, I'll give this a shot. :)
Title: Re: Mecanim Follow Action
Post by: FritsLyn 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 :)
Title: Re: Mecanim Follow Action
Post by: jeanfabre 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