Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: jeanfabre on January 08, 2013, 03:22:00 PM

Title: Vector2 to Vector3
Post by: jeanfabre 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
Title: Re: Vector2 to Vector3
Post by: nilton_felicio on March 04, 2013, 11:05:17 AM
It was everything I was looking for. Thank you Jean Fabre
Title: Re: Vector2 to Vector3
Post by: szomaza 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
Title: Re: Vector2 to Vector3
Post by: Alex Chouls 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.
Title: Re: Vector2 to Vector3
Post by: szomaza 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.
Title: Re: Vector2 to Vector3
Post by: jeanfabre on February 13, 2019, 07:36:26 AM
Hi,

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

Bye,

 Jean
Title: Re: Vector2 to Vector3
Post by: Padenlee 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
Title: Re: Vector2 to Vector3
Post by: jeanfabre on June 19, 2019, 04:08:06 AM
Hi,

 yes, they were:

(https://i.imgur.com/PMEIiw3.png)

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