How to get rotation of an object using C#
This is the code that I have written to get an object rotation
The object’s X rotation is 45
But on the console I am getting 0.3826835
In the code I have written local rotation but I want global rotation
c.transform.location is a quaternion
In theinspector, the rotation is shown in euler angles
Answer by mikelortega · May 31, 2016 at 01:59 PM
c.transform.localRotation.eulerAngles.x
This isn't working for me, I am getting a value not even close to the actual in inspector during runtime. Any changes? Please help
Answer by pjkokane21 · Sep 10, 2021 at 05:01 AM
[PROBLEM SOLVED]
.
Skip all the above coments.
.
I found a way to get the exact rotation values as in INSPECTOR
.
.
I am showing for angle (x)
,The code is as follow
.
public Transform GameObject;
void Update()
{
float Rotation;
if(GameObject.eulerAngles.x <= 180f)
{
Rotation = GameObject.eulerAngles.x;
}
else
{
Rotation = GameObject.eulerAngles.x - 360f;
}
}
Answer by wes4ray · May 09 at 09:08 PM
Have you tried using Visual Scripting or Bolt? if you are new to coding these could help with learning what things do and not so much did i spell something wrong. you can also watch your script in action as it runs.