I have a simple flying script. it works. however i am trying to limit the z rotation or “roll” of my object.
it flys around great, however if for example I fly up at a 45 degree angle then turn, the object stays at a rotated angle,
I have tried setting my transform.Rotate(-pitch, yaw, 0); but … it does nothing to change what I have done, I have read the scripting references for Transform.Rotate http://docs.unity3d.com/Documentation/ScriptReference/Transform.Rotate.html, but i’m not getting any more info from them.
could someone please point me in the right direction?
I am looking to either auto rotate back into position, or to keep it from “rolling” at all.
this is my code:
using UnityEngine;
using System.Collections;
public class flyscript2 : MonoBehaviour {
public float AmbientSpeed = 100.0f;
public float RotationSpeed = 50.0f;
void Update(){
float roll = 0;
float pitch = 0;
float yaw = 0;
float currot = 0;
//direction
roll = Input.GetAxis("roll") * (Time.deltaTime * RotationSpeed);
pitch = Input.GetAxis("pitch") * (Time.deltaTime * RotationSpeed);
yaw = Input.GetAxis("yaw") * (Time.deltaTime * RotationSpeed);
transform.Rotate(-pitch, yaw, -roll);
//forward
Vector3 AddPos = Vector3.forward;
AddPos = rigidbody.rotation * AddPos;
rigidbody.velocity = AddPos * (Time.deltaTime * AmbientSpeed);
}
}
thank you,
gathos.