I’m working on creating a circular motion while the object itself rotates to follow the circular path it is on. While the motion isn’t much of a problem, the rotation seems to be slightly off and I can’t figure out why.
I use the code below to move the object, as well as rotate it. While it seems to be -almost- fine, the rotation always seems to be off just a bit. I’ve traced a few things and found out the following: When I set the angle to zero, by my code the rotation of the object should be 360 degrees when I run the script. When I trace the yRotation variable it reflects this nicely. However, when I look at the actual rotation in the editor it gives me a rotation on the y-axis of 106.
I try not to use Rotate.LookAt, Transform.RotateAround or anything of the sort.
Does anyone know why this is?
void Update () {
angle += Input.GetAxis("Horizontal")*10*Time.deltaTime;
Vector3 newPosition = transform.position;
newPosition.x = Center.x + radius*Mathf.Cos(angle);
newPosition.z= Center.z + radius*Mathf.Sin(angle);
float yRotation = 360 - angle;
print(yRotation);
transform.rotation = Quaternion.EulerAngles(0,yRotation,0);
transform.position = newPosition;
}