playMaker

Author Topic: Mathf.Sign  (Read 2908 times)

zorranco

  • Junior Playmaker
  • **
  • Posts: 50
Mathf.Sign
« 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!
« Last Edit: October 22, 2015, 06:06:44 AM by zorranco »

zorranco

  • Junior Playmaker
  • **
  • Posts: 50
Re: Mathf.Sign
« Reply #1 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);
}
}
}

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Mathf.Sign
« Reply #2 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
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

dudebxl

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

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Mathf.Sign
« Reply #4 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