playMaker

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

julius

  • Playmaker Newbie
  • *
  • Posts: 15
vector3 Compare[SOLVED]
« 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 "";
}
}
}
« Last Edit: March 18, 2013, 03:04:19 AM by jeanfabre »

jeanfabre

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

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

bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: vector3 Compare
« Reply #2 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

Andrew.Lukasik

  • Full Member
  • ***
  • Posts: 134
    • my twitter @andrewlukasik
Re: vector3 Compare
« Reply #3 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).

Alatriste

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

Gua

  • Beta Group
  • Sr. Member
  • *
  • Posts: 309
    • Andrii Vintsevych
Re: vector3 Compare[SOLVED]
« Reply #5 on: February 13, 2014, 02:40:16 AM »
This should be a native action IMO.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: vector3 Compare[SOLVED]
« Reply #6 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.
« Last Edit: July 15, 2014, 02:18:05 PM by Lane »
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

MlleBun

  • Playmaker Newbie
  • *
  • Posts: 28
Re: vector3 Compare[SOLVED]
« Reply #7 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?
« Last Edit: August 03, 2020, 08:02:02 AM by MlleBun »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: vector3 Compare[SOLVED]
« Reply #8 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?
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D