playMaker

Author Topic: Get Distance without using Y [SOLVED]  (Read 4244 times)

WitchTheWicked

  • Playmaker Newbie
  • *
  • Posts: 8
Get Distance without using Y [SOLVED]
« on: December 31, 2011, 06:31:31 PM »
I tried my best to make an action script for playmaker but, I didn't get very far, spent a few hours looking at the API reference, there's a lot of TODO for the classes, not blaming that, but I need help please

Function Description : Gets distance between two gameobjects ignoring an AXIS (y).

I would like if a staff member could help me please. Thank you!


Code: [Select]
using UnityEngine;
using System.Collections;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GameObject)]
[Tooltip("Gets distance without the Y axis involved.")]
public class GetDistNoY : FsmStateAction
{
[RequiredField]
        [UIHint(UIHint.FsmGameObject)]
public FsmGameObject objectSrc;

        [UIHint(UIHint.FsmGameObject)]
        public FsmOwnerDefault objectDest;

[UIHint(UIHint.FsmFloat)]
public FSMFloat storeResult;

public bool everyFrame;

public override void Reset()
{
definition = null;
theValue = null;
storeResult = null;
everyFrame = false;
}

public override void OnEnter()
{
DoFindDistanceNoY();

if (!everyFrame)
Finish();
}

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

void DoFindDistanceNoY()
{
            Transform transformSrc = objectSrc.GetComponent<Transform>();
            Transform transformDest = objectDest.GetComponent<Transform>();

            storeResult.Value = transformSrc.position.x;
            print(storeResult.Value);
}

}
}
« Last Edit: January 14, 2012, 07:30:23 PM by alexchouls »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Distance without using Y
« Reply #1 on: January 02, 2012, 03:29:14 AM »
Hi,

 ok, here we go: http://hutonggames.com/playmakerforum/index.php?topic=975.0

Basically you were not far from an playmaker action implementation point of view, it's only the math and logic of the distance computation that was not really the right one.

I made that action more flexible by allowing you to ignore any or a combination of axis. so to ignore the y axis check the "ignore Y" and you will get the distance between two object on the world XZ plane.

 If you need more help, don't hesitate :)

 Bye,

 Jean