playMaker

Author Topic: Vector3 to Vector2  (Read 4111 times)

collidernyc

  • Playmaker Newbie
  • *
  • Posts: 9
Vector3 to Vector2
« 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;
}
}
}

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Vector3 to Vector2
« Reply #1 on: July 03, 2014, 09:18:41 AM »
Hi,

 Thanks for that. This action is also available on the Ecosystem.

 Bye,

 Jean