0

I'm getting from a sensor 4 parameters every frame, O (origin), W (UP), V(FORWARD) and U(RIGHT), they are Vector3 elements, with this values i can know the position of my object is in space, but i can't find out the rotation to represent all movemets that the object does.

this is what i get so far(this run every frame with new values for entry vector):

Vector3 vetO = new Vector3(entry[0], entry[4], entry[8]); //o
Vector3 vetU = new Vector3(entry[1], entry[5], entry[9]); //u
Vector3 vetV = new Vector3(entry[2], entry[6], entry[10]); //v
Vector3 vetW = new Vector3(entry[3], entry[7], entry[11]); //w

//Here i'm doing this to analize the rotation of a plan
vetW.x = 0;
vetU.z = 0;
vetV.y = 0;

float angleX = Vector3.Angle(vetW, Vector3.up);
float angleY = Vector3.Angle(vetV, Vector3.forward);
float angleZ = Vector3.Angle(vetU, Vector3.right);

//This is because unity bug, when angle is up to 180º
angleX = vetW.z < 0 ? -angleX : angleX;
angleY = vetV.x < 0 ? -angleY : angleY;
angleZ = vetU.y < 0 ? -angleZ : angleZ;

Vector3 angles  = new Vector3(angleX, angleY, angleZ);
transform.eulerAngles = angles;
transform.localPosition = vetO;

1 Answer 1

0

If I understand you correctly, you want to get the rotation of a certain gameobject, right?

To do this, you can use YourGameObject.transform.rotation.eulerAngles to give you a rotation in the form of Vector3. If you wanted to get just one angle you can use YourGameObject.transform.rotation.eulerAngles.x,YourGameObject.transform.rotation.eulerAngles.y or YourGameObject.transform.rotation.eulerAngles.z

2
  • actually i have a series of space position and i want to extract the angles between one position and another. May 19, 2016 at 16:53
  • 1
    So you want to get the angle in between 2 objects? (sorry, but I don't really understand what you want) May 19, 2016 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.