Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: julius on January 31, 2013, 11:09:48 PM

Title: vector3 Compare[SOLVED]
Post by: julius on January 31, 2013, 11: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 "";
}
}
}
Title: Re: vector3 Compare
Post by: jeanfabre on February 08, 2013, 02:01:56 AM
Hi,

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

bye,

 Jean
Title: Re: vector3 Compare
Post by: jeanfabre on February 08, 2013, 02: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
Title: Re: vector3 Compare
Post by: Andrew.Lukasik on February 17, 2013, 12:37:28 PM
Yees I needed that. Thanks for sharing Julius!
I wonder why there is no such action in official set (vote+1 to be there).
Title: Re: vector3 Compare[SOLVED]
Post by: Alatriste on February 02, 2014, 09:32:57 AM
Thanks for this! :)
Title: Re: vector3 Compare[SOLVED]
Post by: Gua on February 13, 2014, 02:40:16 AM
This should be a native action IMO.
Title: Re: vector3 Compare[SOLVED]
Post by: Lane on May 20, 2014, 08:44:05 AM
Made it a .cs file for easier access =)

Update 15Jul2014: This action has been cloned in Ecosystem (https://hutonggames.fogbugz.com/default.asp?W1181).
Title: Re: vector3 Compare[SOLVED]
Post by: MlleBun on August 03, 2020, 07:57:37 AM
Hi @Lane. Is there a documentation on Vector3.Compare? Many thanks!
Also, isn't there a Less/Greater than test like the Float.Compare does?
Title: Re: vector3 Compare[SOLVED]
Post by: Lane on August 03, 2020, 01:54:09 PM
Hi @Lane. Is there a documentation on Vector3.Compare? Many thanks!
Also, isn't there a Less/Greater than test like the Float.Compare does?

There may be a greater/lesser than action on ecosystem.

The Compare action will compare the xyz of both of the vectors to see if all 3 comparisons (x to x, y to y, z to z) are within the threshold amount, then fire an event.

Does that answer your question?