I want the object to keep on moving by every frame (using the Time.deltaTime) by clockwise & anti-clockwise rotation.
The player will put the angle they want the object to rotate. Lets say, the angle is 70. After the object is rotate to 70 degree, then it should rotate -70 degree.
public class Rotate : MonoBehaviour {
public enum Direction
{ NONE,RIGHT, LEFT,FORWARD,BACKWARD,DOWN,UP };
public bool Enabled=false;
public GameObject kiub;
[System.Serializable]
public class Rotation {
public bool RotateEnabled = false;
public Direction RotateDirection;
public float RotateSpeed=10;
public float Angle;
}
public Rotation ObjectRotation;
[System.Serializable]
public class Movement {
public bool MovementEnabled = false;
public Vector3 MovementAxis;
public float MovementUnit=0.0001f;
}
public Movement ObjectMovement;
void Update () {
if (Enabled) {
if (ObjectRotation.RotateEnabled) {
if (ObjectRotation.RotateDirection == Direction.UP) {
if(kiub.transform.rotation.eulerAngles.y <= ObjectRotation.Angle)
{
transform.Rotate (Vector3.up * Time.deltaTime * ObjectRotation.RotateSpeed);
}
if(kiub.transform.rotation.eulerAngles.y >= (ObjectRotation.Angle + 0.001))
{
transform.Rotate (Vector3.up * (-Time.deltaTime) * ObjectRotation.RotateSpeed);
}
}
}
}
}
}
So far, transform.Rotate (Vector3.up * Time.deltaTime * ObjectRotation.RotateSpeed); does work. and it work perfectly the way i want it. BUT, when i want it to rotate the other way around by using transform.Rotate (Vector3.up * (-Time.deltaTime) * ObjectRotation.RotateSpeed);, it only rotate to 359 only. no matter how much the value of the ObjectRotation.Angle is.
Please help me for this. Thank you so much. i really dont have any idea why it happen that way, and how to fix it. Please. Thank you.
By the way, i get the idea of (-Time.deltaTime) from Rotating Objects and Sprites in Unity3D using CS (C#) – John Stejskal : Software and Game Developer