Playmaker Forum
PlayMaker Feedback => Action Requests => Topic started by: zorranco on October 22, 2015, 04:50:46 AM
-
Hello, actually the only way to do this is by float compare and spliting execution into other states...it would be great to have a mathf.sign action instead that could be executed every frame.
Thanks!
-
Ok, I am not a coder but keeping attention on how PM scripts work I made a custom action. It works flawlessly, but I don't know if there is some mistake in the script. I doubt if "using Unityengine" and "using System.collections" is right, but otherwise Mathf.Sign was "not present in the current context".
The code:
// (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.
using UnityEngine;
using System.Collections;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Math)]
[Tooltip("Returns 1 for positive or -1 for negative")]
public class FloatSign : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmFloat floatVariable;
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmFloat floatSign;
public bool everyFrame;
public override void Reset()
{
floatVariable = null;
floatSign = null;
everyFrame = false;
}
public override void OnEnter()
{
floatSign.Value = Mathf.Sign (floatVariable.Value);
if (!everyFrame)
Finish();
}
public override void OnUpdate()
{
floatSign.Value = Mathf.Sign (floatVariable.Value);
}
}
}
-
Hi,
That looks good! Fits right in with the pattern of other actions and if your tests are good then its a solid action =)
I thought we had this action floating around somewhere already but nonetheless this works. Keep poking around in code - you'll be surprised what you learn :D
-
+1 add to ecosystem please ;D
-
Hi,
Definitly. I made a video to show you how to distribute your actions on the ecosystem.
Bye,
Jean