- Home /
Converting www.text or string to rotation or position
How do you convert a string to a rotation (quat) or position (vector3) value?
Format: var strQ:String = "(0,0,0,1)";
or var strV:String="(1,3,5)";
... how do you conver the strQ to a quaternion and the strV to a vector?
Answer by Edwige · Feb 01, 2011 at 05:38 PM
This is not a real answer, but it may helps anyway.
I had the same issue : I stored character position (Vector3) in my database, and I had hard time retrieving it. Finally, I find it easier to store float in my database for each value.
posperso is a Vector3 where is stored my position. For the form, I send it like that :
var posx : float = posperso.x;
var posy : float = posperso.y;
var posz : float = posperso.z;
var posxstr = posx.ToString();
var posystr = posy.ToString();
var poszstr = posz.ToString();
So, in my database, I have 3 fields instead of 1.
When retrieving these data, in my php code, I have just put a blank between the values.
Then, back in Unity again :
var tab : Array = new Array();
tab = formText.Split(" " [0]);
var posx : float = float.Parse(tab[0]);
var posy : float = float.Parse(tab[1]);
var posz : float = float.Parse(tab[2]);
posPerso.x =posx;
posPerso.y =posy;
posPerso.z =posz;
Answer by Maarten · Jan 14, 2011 at 12:43 PM
It all depends on how the string is presented. So you need to write something that converts your string to the needed type.
So without any information about how the string is presented, i cant give you an helpfull answer.
Say you have a string in the form of a Quaternion stringvar ="(0,0,0,1)"
for example or Vector 3 (1,3,5) for example..
Your answer
Follow this Question
Related Questions
[Unity 3D] How to detect if the game object is left right from the player? 0 Answers
How to Rotate like b.transform.rotation = Quaternion.Euler(x, y, z); ? 1 Answer
Get direction of moving sphere? 1 Answer
how to CORRECTLY position and rotate a gameobject in unity 2 Answers
How to make Canvas follow CameraRig [VR - HTC VIVE] 0 Answers