- Home /
Not Enough Rotation
Hi, I'm trying to make the saucer shape below turn clockwise or anticlockwise by pressing the "z" or "c" key.

I can only make the saucer turn clockwise or anticlockwise about 1 or 2 degrees. How can I make the saucer turn more, even 360 degrees? My code is below:
 using UnityEngine;
 using System.Collections;
 
 public class LimitRotate : MonoBehaviour {
 public float rotationSpeed = 100.0f;
 public float MaxTiltAngle = 20.0f;
 public float tiltSpeed = 30.0f; // tilting speed in degrees/second
  
 Vector3 curRot;
 float maxX;
 float maxZ;
 float minX;
 float minZ;
 
     
 void Start () {
     // Get initial rotation
     curRot = this.transform.eulerAngles;
     // calculate limit angles:
     maxX = curRot.x + MaxTiltAngle;
     maxZ = curRot.z + MaxTiltAngle;
     minX = curRot.x - MaxTiltAngle;
     minZ = curRot.z - MaxTiltAngle;
     }
  
 void Update () {
     // "rotate" the angles mathematically:
     curRot.x += Input.GetAxis("Vertical") * Time.deltaTime * tiltSpeed;
     curRot.z += Input.GetAxis("Horizontal") * Time.deltaTime * tiltSpeed;
     // Restrict rotation along x and z axes to the limit angles:
     curRot.x = Mathf.Clamp(curRot.x, minX, maxX);
     curRot.z = Mathf.Clamp(curRot.z, minZ, maxZ);
  
     float rotation = Input.GetAxis ("Rotate") * rotationSpeed;
     rotation *= Time.deltaTime;
         
     // Set the object rotation
     this.transform.eulerAngles = curRot;
     transform.Rotate (0, rotation, 0);
     }
 
 }
Answer by create3dgames · Jul 14, 2013 at 05:45 PM
On line 35, instead of rotation *= Time.deltaTime, do rotation *= Time.deltaTime*50 
Answer by robertbu · Jul 14, 2013 at 07:51 PM
You are mixing an absolute rotation on line 38 with a relative rotation on line 39. So each time you execute line 38, you reset the 'Y' rotation back to 0. Here is a modification of your code that may be what you are looking for:
 using UnityEngine;
 using System.Collections;
  
 public class LimitRotate : MonoBehaviour {
 public float rotationSpeed = 100.0f;
 public float MaxTiltAngle = 20.0f;
 public float tiltSpeed = 30.0f; // tilting speed in degrees/second
  
 Vector3 curRot;
 float maxX;
 float maxZ;
 float minX;
 float minZ;
  
  
 void Start () {
     // Get initial rotation
     curRot = this.transform.eulerAngles;
     // calculate limit angles:
     maxX = curRot.x + MaxTiltAngle;
     maxZ = curRot.z + MaxTiltAngle;
     minX = curRot.x - MaxTiltAngle;
     minZ = curRot.z - MaxTiltAngle;
     }
  
 void Update () {
     // "rotate" the angles mathematically:
     curRot.x += Input.GetAxis("Vertical") * Time.deltaTime * tiltSpeed;
     curRot.z += Input.GetAxis("Horizontal") * Time.deltaTime * tiltSpeed;
     curRot.y += Input.GetAxis ("Rotate") * Time.deltaTime * rotationSpeed;
     // Restrict rotation along x and z axes to the limit angles:
     curRot.x = Mathf.Clamp(curRot.x, minX, maxX);
     curRot.z = Mathf.Clamp(curRot.z, minZ, maxZ);
   
     transform.eulerAngles = curRot;
     }
 }
Answer by kildare268 · Jul 15, 2013 at 02:28 PM
Thanks robertu and create3dgames! Both your methods worked!
Your answer
 
 
             Follow this Question
Related Questions
Rotate Around Object 2 Answers
Turn page, smooth rotate 1 Answer
How to rotate terrain or tilt it for z axis when play mode? (C#) just think of it as an object 0 Answers
Why rotating around X and Y axis using transform.Rotate rotates around z axis as well ? 1 Answer
Transform.Rotate producing unexpected results when being used after setting localEulerAngles 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                