Playmaker Forum
PlayMaker Updates & Downloads => Share New Actions => Topic started 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.
// (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
-
It was everything I was looking for. Thank you Jean Fabre
-
Thank you for this. Just what I needed.
Please also put it onto the Ecosystem.
br,
szomaza
-
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.
-
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.
-
Hi,
True :) good point, I'll up now on the Ecosystem.
Bye,
Jean
-
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
-
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