hey im trying to simulate a plane, but when i try to make it rotate it starts to go faster and faster(i know the AddRelativeTorque does that), but i want to add a max and i cant think of a way to do this. here is the code i used:
@HideInInspector
var xRotation : float;
@HideInInspector
var yRotation : float;
@HideInInspector
var zRotation : float;
var maxRotation : float = 7;
var rotSensibility : float = 7;
function Update(){
xRotation = Input.GetAxis("Vertical") * rotSensibility * Time.deltaTime;
yRotation = Input.GetAxis("Horizontal") * rotSensibility * Time.deltaTime;
zRotation = Input.GetAxis("Roll") * rotSensibility * Time.deltaTime;
rigidbody.AddRelativeTorque(xRotation, yRotation, zRotation);
if (Input.GetAxis("Horizontal") == 0){
rigidbody.AddRelativeTorque(xRotation, 0, zRotation);
}
if (Input.GetAxis("Vertical") == 0){
rigidbody.AddRelativeTorque(0, yRotation, zRotation);
}
if (Input.GetAxis("Vertical") == 0){
rigidbody.AddRelativeTorque(xRotation, yRotation, 0);
}
}