- Home /
How to find an object's rotation in 2D
Hello,
So I have this object in 2D that rotates 90 degrees every time it is clicked. So there are four cases. How can I know the object's exact rotation? The object's parent also rotates the same way. EulerAngles and transform.rotation seem to give random numbers.
Any ideas?
transform.rotation
is a QUATERNION giving the rotation in the world spacetransform.localRotation
is a QUATERNION giving the rotation in the parent spacetransform.eulerAngles
is a VECTOR3 giving the rotation in the world spacetransform.localEulerAngles
is a VECTOR3 giving the rotation in the parent space, it's the values you see in the inspector
I've tried those and I always get random/weird numbers from both methods! $$anonymous$$y question is basically how can I know an object's rotation in degrees using these?
transform.eulerAngles
should give you what you want. Can you edit your question and post screenshot with the object rotated and the values returned by transform.eulerAngles
?
Answer by Dankey_Kang · Oct 04, 2018 at 02:51 PM
Perhaps try using Vector2.SignedAngle in combination with transform.up and Vector2.up. You might need to flip the process with a negative in front of the signed_angle depending on wether you want it clockwise or not.
Vector2 obj_up = (Vector2) transform.up;
float signed_angle = Vector2.SignedAngle(obj_up, Vector2.up);
float angle = signed_angle;
if (angle < 0) {
angle += 360f;
}
Or you can use transform.eulerAngles which is supposed to give you the rotation in degrees of the object around each axis, in your case you would want to look at the z axis for the rotation, although you mentioned you were having trouble with that one.
Your answer
Follow this Question
Related Questions
Worldspace EulerAngle.x regardless of z rotation ? 3 Answers
Rotation drift with transform.eulerAngles 0 Answers
transform bullitprefab errors 0 Answers
eulerAngles.y always returns 179.9999 1 Answer
Rotation promlems past 90 and 270 3 Answers