playMaker

Author Topic: Mathf.Sign  (Read 1662 times)

zorranco

  • Playmaker Newbie
  • *
  • Posts: 44
    • View Profile
Mathf.Sign
« on: October 22, 2015, 01: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!
« Last Edit: October 22, 2015, 03:06:44 AM by zorranco »

zorranco

  • Playmaker Newbie
  • *
  • Posts: 44
    • View Profile
Re: Mathf.Sign
« Reply #1 on: October 22, 2015, 03: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);
}
}
}

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2488
  • Yup.
    • View Profile
    • Cleverous
Re: Mathf.Sign
« Reply #2 on: October 22, 2015, 04: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

dudebxl

  • Hero Member
  • *****
  • Posts: 602
    • View Profile
Re: Mathf.Sign
« Reply #3 on: October 23, 2015, 11:15:12 AM »
+1 add to ecosystem please  ;D

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14684
  • Official Playmaker Support
    • View Profile
Re: Mathf.Sign
« Reply #4 on: November 16, 2015, 05:53:25 AM »
Hi,

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


Bye,

 Jean