playMaker

Author Topic: Vector2 to Vector3  (Read 10845 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Vector2 to Vector3
« on: January 08, 2013, 03: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
Re: Vector2 to Vector3
« Reply #1 on: March 04, 2013, 11:05:17 AM »
It was everything I was looking for. Thank you Jean Fabre

szomaza

  • Sr. Member
  • ****
  • Posts: 253
Re: Vector2 to Vector3
« Reply #2 on: February 10, 2019, 11: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: 3985
  • Official Playmaker Support
    • LinkedIn
Re: Vector2 to Vector3
« Reply #3 on: February 10, 2019, 11: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

  • Sr. Member
  • ****
  • Posts: 253
Re: Vector2 to Vector3
« Reply #4 on: February 11, 2019, 02: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: 15500
  • Official Playmaker Support
Re: Vector2 to Vector3
« Reply #5 on: February 13, 2019, 07:36:26 AM »
Hi,

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

Bye,

 Jean

Padenlee

  • Junior Playmaker
  • **
  • Posts: 63
  • You can't hit what you don't shoot for!
Re: Vector2 to Vector3
« Reply #6 on: June 17, 2019, 03:55:28 PM »
For some reason Vector2 to Vector3 is not on the Ecosystem and Vector3 to Vector2 and Vector2 To Vector3 display typos in the title "Vector3to Vector2", "Vector2to Vector3"

I also suggest changing the names to
"Convert Vector3 To Vector2"
"Convert Vector2 To Vector3"

And also place both under the Convert category
« Last Edit: June 17, 2019, 03:58:01 PM by Padenlee »
-Paden Pierry
@padenpierry
Apple inc.'s first TV show, EP 1.
Game Dev since 2007
Coolest client: Bridgestone

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Vector2 to Vector3
« Reply #7 on: June 19, 2019, 04:08:06 AM »
Hi,

 yes, they were:



But I agree, they should be renamed, and I just did, so now you can search with Convert key word.

 I also fixed the naming to avoid bad wording separation.

 Bye

 Jean

Bye,

 Jean