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);
}
}