playMaker

Author Topic: vector3 Compare[SOLVED]  (Read 4725 times)

julius

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
vector3 Compare[SOLVED]
« on: January 31, 2013, 09:09:48 PM »
vector3 Compare
Hey all!

I saw someone post about this but couldn't find an action for it so here it is!

Also just to ask the question, I normally reference code form other actions when I make mine so should I leave the "// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved." in my actions?

*edit* I forgot to write out what it does! It compares two vecor3 variables with a tolerance and returns equal or not equal.

I've been using it to check if an object has moved/scaled or not.

*edit 2*
Fixed tooltip! Thanks Jean.

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Logic)]
[Tooltip("Sends Events based on the comparison of 2 Vector3's.")]
public class Vector3Compare : FsmStateAction
{
[RequiredField]
public FsmVector3 vector3Variable1;
[RequiredField]
public FsmVector3 vector3Variable2;
[RequiredField]
public FsmFloat tolerance;
[Tooltip("Event sent if Vector3 1 equals Vector3 2 (within Tolerance)")]
public FsmEvent equal;
[Tooltip("Event sent if the Vector3's are not equal")]
public FsmEvent notEqual;
public bool everyFrame;

public override void Reset()
{
vector3Variable1 = null;
vector3Variable2 = null;
tolerance = 0f;
equal = null;
notEqual = null;
everyFrame = false;
}

public override void OnEnter()
{
DoCompare();

if (!everyFrame)
Finish();
}

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

void DoCompare()
{
if (vector3Variable1 == null || vector3Variable2 == null) return;

if (Mathf.Abs(vector3Variable1.Value.x - vector3Variable2.Value.x) <= tolerance.Value
&& Mathf.Abs(vector3Variable1.Value.y - vector3Variable2.Value.y) <= tolerance.Value
&& Mathf.Abs(vector3Variable1.Value.z - vector3Variable2.Value.z) <= tolerance.Value)
{
Fsm.Event(equal);
return;
} else {
Fsm.Event(notEqual);
}

}

public override string ErrorCheck()
{
if (FsmEvent.IsNullOrEmpty(equal) &&
FsmEvent.IsNullOrEmpty(notEqual))
return "Action sends no events!";
return "";
}
}
}
« Last Edit: March 18, 2013, 12:04:19 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14035
  • Official Playmaker Support
    • View Profile
Re: vector3 Compare
« Reply #1 on: February 08, 2013, 12:01:56 AM »
Hi,

one small thing. you forgot to edit the tooltip for the action :)

bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14035
  • Official Playmaker Support
    • View Profile
Re: vector3 Compare
« Reply #2 on: February 08, 2013, 12:02:56 AM »
Hi,

 you don't have to keep the copyright, but that's a nice thing to do anyway, never hurts. you can put your details as well, that's also perfectly acceptable.

bye,

 Jean

Andrew.Lukasik

  • Full Member
  • ***
  • Posts: 134
    • View Profile
    • my twitter @andrewlukasik
Re: vector3 Compare
« Reply #3 on: February 17, 2013, 10:37:28 AM »
Yees I needed that. Thanks for sharing Julius!
I wonder why there is no such action in official set (vote+1 to be there).

Alatriste

  • Full Member
  • ***
  • Posts: 179
    • View Profile
Re: vector3 Compare[SOLVED]
« Reply #4 on: February 02, 2014, 07:32:57 AM »
Thanks for this! :)

Gua

  • Full Member
  • ***
  • Posts: 145
    • View Profile
    • Andrii Vintsevych
Re: vector3 Compare[SOLVED]
« Reply #5 on: February 13, 2014, 12:40:16 AM »
This should be a native action IMO.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2488
  • Yup.
    • View Profile
    • Cleverous
Re: vector3 Compare[SOLVED]
« Reply #6 on: May 20, 2014, 05:44:05 AM »
Made it a .cs file for easier access =)

Update 15Jul2014: This action has been cloned in Ecosystem.
« Last Edit: July 15, 2014, 11:18:05 AM by Lane »