- Home /
Object rotation in code is different than it is in game?
I'm trying to provide a unit with a floating health bar. To keep the health bar horizontal while it is the child of that object, i subtract the objects rotation.eulerAngles.z from 360. This gives me the appropriate numbers to keep the health bar rotated in such a way that it is always horizontal. It was not working, I kept getting the inverse rotation for some reason. I did some debugging and the numbers showing up in the code where different than the ones showing up in game. I even eliminated the math and just set the rotation with a constant.
No matter what the rotation is set to in the code it seems to be set to the inverse of the difference of 360 minus that rotation in game.
If I set the rotation to (0,0,350) in code, in game it's (0,0,340). 360 - 350 = 10. The inverse rotation of 10 is 340.
If I set the rotation to (0,0,270) in code, in game it's (0,0,180). 360 - 270 = 90. The Inverse rotation of 90 is 180.
What is going on here, and how do I fix it? I'm completely baffled.
Answer by ProtoTerminator · Mar 22, 2015 at 02:12 AM
You're setting world rotation, while the inspector shows local rotation. To set local rotation, use transform.localRotation.
Your answer
Follow this Question
Related Questions
How to adjust rotation of map icon with a gameObject.transform.rotation 0 Answers
Why Is Rotation Different For RectTransform? 0 Answers
Trying to rotate a 2D image over time to a specific angle, but it's rotating its Y value every time 1 Answer
Rotate rect transform ui by touch 0 Answers
Why does only the first of sequential quaternion operations work? 1 Answer