- Home /
eulerAngles/rotation halts abruptly
I've hit an issue with eulerAngles and I just can't figure out what's going wrong. Hoping to gain some insight.
Essentially I'm trying to model a satellite whose Y axis is always facing the origin (0,0,0) while it also spins around it's X axis.
void Update(){
myTransform.eulerAngles = new Vector3(Spin(myTransform.eulerAngles.x),facingAngle(),0);
}
My problem is with the Spin() return values, it increments as intended until it the angle reaches 90 and then stays there.
float facingAngle()
{
float temp = Mathf.Atan2(myTransform.position.z,myTransform.position.x);
return -temp * Mathf.Rad2Deg;
}
float Spin(float last)
{
Debug.Log("Last: " + last);
float temp = last + 15 * Time.deltaTime;
Debug.Log("DeltaTime: " + (15 * Time.deltaTime));
if(temp > 360)
temp -= 360;
Debug.Log("Return: " + temp);
return temp;
}
I'm not getting any errors or warnings, the debug logs have the proper values up until the return value, the object behaves properly when both orbiting and rotating until 90. At this point I'm sure there's something wrong with either my Time.deltaTime placement or the way I'm feeding the angles to myTransform but I'm not familiar enough with Unity to know what.
Any help would be appreciated, thank you in advance.
Answer by FishBone · May 10, 2012 at 11:11 AM
transform.eulerAngles when x is rotated more then 90 degrees will return (90, 180, 180) and count down on x, instead of going to (91, 0, 0). I would just for simplicity have the x-rotation as a variable and use that (since you are just adding to it anyway).
so it could be something like:
float _xRotation = 0;
void Spin()
{
_xRotation += 15 * Time.deltaTime;
//you don't really need to do this
if(_xRotation > 360)
_xRotation -= 360;
}
void Update(){
Spin();
myTransform.eulerAngles = new Vector3(_xRotation,facingAngle(),0);
}
Your answer
Follow this Question
Related Questions
How to get inspector rotation values ? 2 Answers
Simulating a Fidget Spinner 1 Answer
Problem when checking a Quaternion Eulerangle axis 1 Answer
Euler Angles question 1 Answer