playMaker

Author Topic: GetDistance between vectors  (Read 6607 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15594
  • Official Playmaker Support
GetDistance between vectors
« on: December 21, 2012, 03:54:09 AM »
Hi,

 following a request:
http://hutonggames.com/playmakerforum/index.php?topic=2757.0

Please find a new version of GetDistance that let you select Vector3 as well as gameObject, so now you have a very flexible way to compute distances.

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

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GameObject)]
[Tooltip("Measures the Distance betweens 2 Game Objects or vectors and stores the result in a Float Variable. Vector3 are offseted to GameObjects if declared")]
public class GetDistance2 : FsmStateAction
{

public FsmOwnerDefault gameObject;

public FsmVector3 orVector3;

public FsmGameObject target;

public FsmVector3 orVector3Target;

[RequiredField]
[UIHint(UIHint.Variable)]
public FsmFloat storeResult;
public bool everyFrame;

public override void Reset()
{
gameObject = null;
orVector3  = null;
target = null;
orVector3Target = null;

storeResult = null;
everyFrame = true;
}

public override void OnEnter()
{
DoGetDistance();

if (!everyFrame)
Finish();
}
public override void OnUpdate()
{
DoGetDistance();
}

void DoGetDistance()
{
GameObject go = gameObject.OwnerOption == OwnerDefaultOption.UseOwner ? Owner : gameObject.GameObject.Value;

if (storeResult == null)
return;

Vector3 start = Vector3.zero;
if (go!=null)
{
start = go.transform.position;
}
start += orVector3.Value;

Vector3 end = Vector3.zero;
if (target.Value!=null)
{
start = target.Value.transform.position;
}
start += orVector3Target.Value;

storeResult.Value = Vector3.Distance(start, end);
}

}
}


bye,

 Jean

Geniraal

  • Playmaker Newbie
  • *
  • Posts: 5
Re: GetDistance between vectors
« Reply #1 on: January 01, 2017, 03:41:04 PM »
 :) Thanks for this work perfect

gozda

  • Junior Playmaker
  • **
  • Posts: 88
Re: GetDistance between vectors
« Reply #2 on: January 01, 2017, 05:28:10 PM »
You answered 4 years later, you have very slow internet:)