- Home /
Need to know euler angles of Vector3 direction relative to other Vector3 direction
I tried this but it dont work as I expected(the results in euler had to be the same)...
Quaternion relative_rot = Quaternion.Inverse(transform.rotation) * Quaternion.LookRotation(Vector3.up);
Vector3 relative_rot_euler = relative_rot.eulerAngles;
Debug.Log("x,y,z : x1,y1,z1 "
+transform.rotation.eulerAngles.x+", "
+transform.rotation.eulerAngles.y+", "
+transform.rotation.eulerAngles.z+" : "
+relative_rot_euler.x+", "
+relative_rot_euler.y+", "
+relative_rot_euler.z );
The primary idea is to measure deviation of direction in euler angles from one vector3 to another.
Answer by Jesse Anders · Dec 10, 2010 at 04:19 AM
The problem may be that you're using Vector3.up as the (first) argument to LookRotation(), which is likely to produce an invalid result. The second (optional) argument to LookRotation() is the reference vector, which defaults to Vector3.up. If the input vector and the reference vector are parallel or nearly parallel (as is the case in the above code), the results are likely to be invalid.
I'm a little skeptical regarding the usefulness of expressing a relative rotation in Euler-angle form, but I'll just assume you have a good reason for wanting to do that.
Thanks for the answer, but the problem is not resolved... I use euler angles to add torque to rigidbody for selective axes. This torque have to be dependent on relative angles between two vector directions(in my case oject`s down and another world vector).. And as a test I used other arguments to LookRotation() - Vector3.forward for example.. And angles for 1 or 2 axes were quite the same as transform.rotation.eulerAngles, but not for all 3 axes.
To be honest, I kind of doubt the approach you're taking here is viable. (That said, I don't know enough about the problem you're trying to solve to suggest an alternative.)
I want to stabilize GO rotation using physics (AddTorque) on x and z axes only with respect to, for example, a normal to terrain or some other vector.. Thats what I`m trying to do =) Now I can stabilize to normal to x-z plane using directl transform.rotation.eulerAngles, but can`t do it for random vector. Will try to experiment more..
It sounds like what you'd want to do here is apply a torque (with appropriate magnitude) that's parallel to the cross product of the game object's local up vector and the vector you want to align with. (Reaching a target orientation using applied torque only can be kind of tricky though - you might be able to find some threads on the topic in the forums.)
Yes, I use PID controller, but I need a feedback of angle (sub of target and current). Tried to add auler angles of two rotations but still could not achieve proper angles.. (((
Your answer
Follow this Question
Related Questions
[2D] Angle to Vector conversion 1 Answer
Relative rotation offset? 2 Answers
Setting rotation angle of a bullet fired towards the mouse 1 Answer
Finding rotation 0 Answers