Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: WitchTheWicked on December 31, 2011, 04:31:31 PM

Title: Get Distance without using Y [SOLVED]
Post by: WitchTheWicked on December 31, 2011, 04: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);
}

}
}
Title: Re: Get Distance without using Y
Post by: jeanfabre on January 02, 2012, 01:29:14 AM
Hi,

 ok, here we go: http://hutonggames.com/playmakerforum/index.php?topic=975.0 (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