- Home /
Rotating with EulerAngles 360 - 0
Okay, I have my player holding a torch that smooth damps to his rotation( to simulate that it actually has some weight to it). However whenever the rotation of the player goeas above 360 or below 0, it has to go all the way round instead of just jumping from 360 to 0 and vice versa. I know why this is happening but can anybody modify the below code to make this work? Thanks!
var targetX : Camera;
var targetY : GameObject;
var rotationX : float;
var rotationY : float;
var fRotationX : float;
var fRotationY : float;
var tRotationX : float;
var tRotationY : float;
var velocityX : float = 0;
var velocityY : float = 0;
var smoothTime : float = 0.3;
function Start ()
{
}
function Update ()
{
transform.position = targetY.transform.position;
tRotationX = targetX.transform.localEulerAngles.x;
rotationX = transform.eulerAngles.x;
fRotationX = Mathf.SmoothDamp(rotationX, tRotationX, velocityX, smoothTime);
transform.eulerAngles.x = fRotationX;
tRotationY = targetY.transform.eulerAngles.y;
rotationY = transform.eulerAngles.y;
fRotationY = Mathf.SmoothDamp(rotationY, tRotationY, velocityY, smoothTime);
transform.eulerAngles.y = fRotationY;
}
ins$$anonymous$$d of going from 360 to 0 i goes from 360 to 0 by going 359, 358..... ins$$anonymous$$d of just going straight to 0
so what your saying is that you have to rotate all the way back to get to zero? does it go above 360? like to 361?
theres no such thing as an angle above 360 in unity
yes there is, if transform.eulerAngles = new Vector3(x , y ,z rotations) and you assign a public float to x, y, or z you will see in the inspector the value of the angle. In this sense the angle will go above 360.
For me to answer your question I need to know what it's doing.
There are two reasons you could be having this problem. 1) you don't realize that the value of your rotation is going over 360 and the eulerAngles have no value to rotate to (because eulerAngles are assigned values between 0-360)
2) it's possible that because you're using smoothdamp the function is saying "okay, we just went from 360 to 0 so lets smoothdamp backwards"
both scenarios are possible, though I don't have the project in front of me so I can't see what's happening
Your answer
![](https://koobas.hobune.stream/wayback/20220613084812im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Euler to Quaternion conversion returns unexpected result at exactly 180 degree rotation on Y axis 0 Answers
Limiting the rotation of an object 1 Answer
Rotation losing precision 0 Answers
Trying to get the angle of a camera object based on players forward, is not distance independent 0 Answers
How can I store the individual values of EulerAngles on a Database then re-apply 2 Answers