- Home /
Space ship controls locking into place
Hello, all. I have the most unusual problem of my space ship control script locking into a rotation and not allowing any input when it reaches the maximum y angle. All help would be appreciated. Here's my code:
var minSpeed : float;
var maxSpeed : float;
var maxAngles : Vector2;
var breakKey : KeyCode;
var accelerateSpeed : float;
var breakSpeed : float;
var rotateSpeed : float;
private var curSpeed : float;
function Awake ()
{
curSpeed = minSpeed;
}
function Update ()
{
if(Input.GetKey(breakKey))
curSpeed -= Time.deltaTime * breakSpeed;
else
curSpeed += Time.deltaTime * accelerateSpeed;
curSpeed = Mathf.Clamp(curSpeed, minSpeed, maxSpeed);
rigidbody.velocity = transform.forward * curSpeed;
var targetAngleX : float = transform.eulerAngles.x + Input.GetAxis("Vertical") * maxAngles.x;
var angleX : float = Mathf.MoveTowardsAngle(transform.eulerAngles.x, targetAngleX, rotateSpeed * Time.deltaTime);
var targetAngleY : float = transform.eulerAngles.y + Input.GetAxis("Horizontal") * maxAngles.y;
var angleY : float = Mathf.MoveTowardsAngle(transform.eulerAngles.y, targetAngleY, rotateSpeed * Time.deltaTime);
var targetAngleZ : float = Input.GetAxis("Horizontal2") * 180;
var angleZ : float = Mathf.MoveTowardsAngle(transform.eulerAngles.z, targetAngleZ, rotateSpeed * Time.deltaTime);
transform.eulerAngles = Vector3(angleX, angleY, angleZ);
}
Comment
Best Answer
Answer by Sir Keyzinburga · Aug 08, 2011 at 03:44 PM
I have attached your script to a cube and disabled the velocity for testing. I have no trouble at all after using some values I saw fit.
After changing some values I have tried to figure out what you want with the maxAngles variable.
May I ask what values you use for it and with what purpose?