playMaker

Author Topic: Animation Graph tutorial  (Read 2580 times)

brown2na

  • Playmaker Newbie
  • *
  • Posts: 1
Animation Graph tutorial
« on: December 02, 2012, 09:41:15 AM »
Hello,

So I'm pretty new to this and I was attempting to follow the animation graph tutorial.
While doing the tutorial I noticed my FSM aren't sending to other events so when the movement speed is below 3 he walks but if movement speed stops at 0 he still walks and above 3 he never runs.

I looked at the code for my FSM and none of the events from the floats point to another state...

Code: [Select]
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Logic)]
[Tooltip("Sends Events based on the comparison of 2 Floats.")]
public class FloatCompare : FsmStateAction
{
[RequiredField]
public FsmFloat float1;
[RequiredField]
public FsmFloat float2;
[RequiredField]
public FsmFloat tolerance;
[Tooltip("Event sent if Float 1 equals Float 2 (within Tolerance)")]
public FsmEvent equal;
[Tooltip("Event sent if Float 1 is less than Float 2")]
public FsmEvent lessThan;
[Tooltip("Event sent if Float 1 is greater than Float 2")]
public FsmEvent greaterThan;
public bool everyFrame;

public override void Reset()
{
float1 = 0f;
float2 = 0f;
tolerance = 0f;
equal = null;
lessThan = null;
greaterThan = null;
everyFrame = false;
}

public override void OnEnter()
{
DoCompare();

if (!everyFrame)
Finish();
}

public override void OnUpdate()
{
DoCompare();
}

void DoCompare()
{

if (Mathf.Abs(float1.Value - float2.Value) <= tolerance.Value)
{
Fsm.Event(equal);
return;
}

if (float1.Value < float2.Value)
{
Fsm.Event(lessThan);
return;
}

if (float1.Value > float2.Value)
{
Fsm.Event(greaterThan);
}

}

public override string ErrorCheck()
{
if (FsmEvent.IsNullOrEmpty(equal) &&
FsmEvent.IsNullOrEmpty(lessThan) &&
FsmEvent.IsNullOrEmpty(greaterThan))
return "Action sends no events!";
return "";
}
}
}

DARK_ETERNAL

  • Full Member
  • ***
  • Posts: 110
Re: Animation Graph tutorial
« Reply #1 on: December 05, 2012, 04:30:05 PM »
Ehh... So.. You want?
Check out our new game: Nitro Chimp. Now live in App Store!

Trailer:
Download: https://itunes.apple.com/app/nitro-chimp/id557150450?l=en&mt=8

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: Animation Graph tutorial
« Reply #2 on: December 05, 2012, 06:40:26 PM »
I think there might be some confusion over terminology. States are connected by transitions. Transitions are triggered by events. The event doesn't directly specify a transition state. It is simply sent, and then the state machine decides what to do with it.

At first this might seem odd when sending events to yourself, but this separation comes in very handy when your state machine setups become more complex and send events to each other... For example a movement FSM might get events from an AI FSM or from a player input FSM - it doesn't care!

Once you start breaking behaviors down into states and events, it becomes a powerful tool to build complex behavior.

Does that make sense? Or have I made it worse! ;)