playMaker

Author Topic: Mecanim Follow Action  (Read 8895 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14059
  • Official Playmaker Support
    • View Profile
Mecanim Follow Action
« on: November 21, 2012, 11:43:32 AM »
------- [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, 12:58:14 AM by jeanfabre »

Dev_Sebas

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

mickman

  • Junior Playmaker
  • **
  • Posts: 60
    • View Profile
Re: Mecanim Follow Action
« Reply #2 on: November 22, 2012, 09: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
    • View Profile
Re: Mecanim Follow Action
« Reply #3 on: November 22, 2012, 09:05:44 PM »
hi,

thanks jean :)

Dev

play_edu

  • Full Member
  • ***
  • Posts: 116
    • View Profile
Re: Mecanim Follow Action
« Reply #4 on: November 22, 2012, 10:00:34 PM »
Hi,


Thanks jean,


 it's Good news for us.


play_edu

Armada Animations

  • Playmaker Newbie
  • *
  • Posts: 3
    • View Profile
Re: Mecanim Follow Action
« Reply #5 on: November 28, 2012, 03: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
    • View Profile
Re: Mecanim Follow Action
« Reply #6 on: November 28, 2012, 11:06:18 PM »
 :)

jeanfabre

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

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

bye,

 Jean

Brighton

  • Playmaker Newbie
  • *
  • Posts: 9
    • View Profile
Re: Mecanim Follow Action
« Reply #8 on: January 27, 2013, 09: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
    • View Profile
Re: Mecanim Follow Action
« Reply #9 on: February 06, 2013, 10:00:16 PM »
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
    • View Profile
Re: Mecanim Follow Action
« Reply #10 on: February 07, 2013, 07: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
    • View Profile
Re: Mecanim Follow Action
« Reply #11 on: February 09, 2013, 01:35:32 AM »
Ah Very cool!

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

FritsLyn

  • Full Member
  • ***
  • Posts: 191
    • View Profile
Re: Mecanim Follow Action
« Reply #12 on: April 11, 2013, 01: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: 14059
  • Official Playmaker Support
    • View Profile
Re: Mecanim Follow Action
« Reply #13 on: April 11, 2013, 11:13:37 PM »
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