Playmaker Forum

PlayMaker Feedback => Action Requests => Topic started by: zorranco on October 22, 2015, 04:50:46 AM

Title: Mathf.Sign
Post 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!
Title: Re: Mathf.Sign
Post by: zorranco on October 22, 2015, 06:06:33 AM
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:
Code: [Select]
// (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);
}
}
}
Title: Re: Mathf.Sign
Post by: Lane on October 22, 2015, 07:16:32 AM
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
Title: Re: Mathf.Sign
Post by: dudebxl on October 23, 2015, 02:15:12 PM
+1 add to ecosystem please  ;D
Title: Re: Mathf.Sign
Post by: jeanfabre on November 16, 2015, 07:53:25 AM
Hi,

 Definitly. I made a video to show you how to distribute your actions on the ecosystem.


Bye,

 Jean