Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: collidernyc on July 02, 2014, 07:24:24 PM

Title: Vector3 to Vector2
Post by: collidernyc on July 02, 2014, 07:24:24 PM
I couldn't find an easy way to do this, so here you go. This just drops the z from the Vector 3, but you can optionally save it as a float.

Code: [Select]
// (c) copyright Hutong Games, LLC 2010-2012. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Vector2)]
[Tooltip("Store a Vector3 XY component into a Vector2 XY component. Drops the Vector3 z component, you can optionally save it to a float.")]
public class Vector3toVector2 : FsmStateAction
{

[UIHint(UIHint.Variable)]
[Tooltip("The vector3")]
public FsmVector3 vector3;

[UIHint(UIHint.Variable)]
[Tooltip("The vector2")]
public FsmVector2 vector2;

[UIHint(UIHint.Variable)]
[Tooltip("Optional z value stored as float")]
public FsmFloat zValue;

public bool everyFrame;

public override void Reset()
{
vector2 = null;
vector3 = null;
everyFrame = false;
}

public override void OnEnter()
{
ConvertVector3toVector2();

if (!everyFrame)
{
Finish();
}
}

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

void ConvertVector3toVector2()
{
vector2.Value = new Vector2(vector3.Value.x,vector3.Value.y);
zValue.Value = vector3.Value.z;
}
}
}
Title: Re: Vector3 to Vector2
Post by: jeanfabre on July 03, 2014, 09:18:41 AM
Hi,

 Thanks for that. This action is also available on the Ecosystem (https://hutonggames.fogbugz.com/default.asp?W1181).

 Bye,

 Jean