playMaker

Author Topic: Vector2 to Vector3  (Read 5526 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 13857
  • Official Playmaker Support
    • View Profile
Vector2 to Vector3
« on: January 08, 2013, 01:22:00 PM »
Hi,

 It's sometimes useful to convert a Vector2 into a Vector3, so I made an action for this. It's especially usefull for converting screen position into vector3 for further computation.


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

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Vector2)]
[Tooltip("Store a Vector2 XY components into a Vector3 XY component. The Vector3 z component is also accessible for convenience")]
public class Vector2toVector3 : FsmStateAction
{

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

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


[Tooltip("The vector3 z value")]
public FsmFloat zValue;

public bool everyFrame;

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

}

public override void OnEnter()
{

vector3.Value = new Vector3(vector2.Value.x,vector2.Value.y,zValue.Value);

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

public override void OnUpdate()
{
vector3.Value = new Vector3(vector2.Value.x,vector2.Value.y,zValue.Value);
}

}
}


bye,

 Jean

nilton_felicio

  • Playmaker Newbie
  • *
  • Posts: 16
    • View Profile
Re: Vector2 to Vector3
« Reply #1 on: March 04, 2013, 09:05:17 AM »
It was everything I was looking for. Thank you Jean Fabre

szomaza

  • Full Member
  • ***
  • Posts: 229
    • View Profile
Re: Vector2 to Vector3
« Reply #2 on: February 10, 2019, 09:08:09 AM »
Thank you for this. Just what I needed.

Please also put it onto the Ecosystem.

br,
szomaza

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3431
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: Vector2 to Vector3
« Reply #3 on: February 10, 2019, 09:27:09 AM »
Note starting in PlayMaker 1.9.0 you can auto-convert variables:
https://hutonggames.fogbugz.com/f/page?W1463

This should reduce the need for lots of convert actions and temporary variables.

szomaza

  • Full Member
  • ***
  • Posts: 229
    • View Profile
Re: Vector2 to Vector3
« Reply #4 on: February 11, 2019, 12:53:42 AM »
Thanks for the heads up. I noticed auto-convert but have not use it yet.

Also with this action it is quite handy that I can directly specify the Z value. With the auto-convert I would need an action to set Z for the vector3.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 13857
  • Official Playmaker Support
    • View Profile
Re: Vector2 to Vector3
« Reply #5 on: February 13, 2019, 05:36:26 AM »
Hi,

 True :) good point, I'll up now on the Ecosystem.

Bye,

 Jean