Hello all.May be the title is not so clear,so I would like to explain it.I am currently making an aircraft game.The controls are simple,press arrow buttons and rotate it around z axis.I managed to do this.The problem is that,I want the aircraft to return its idle position smoothly if no arrow keys are pressed.I tried some code but it didn’t work.I really appreciate any help.Thank you!
Here my code to turn it:
using UnityEngine;
using System.Collections;
public class CarController : MonoBehaviour {
private float sensitivity = 70;
private float speed = 40;
public float zRotate;
public float backReturn;
private bool rightArrowUp = false;
void Update () {
// change position by arrow keys
transform.position += new Vector3(Input.GetAxis("Horizontal")*speed*Time.deltaTime,0,0);
// change rotation by arrow keys
zRotate -= Input.GetAxis("Horizontal")*sensitivity*Time.deltaTime;
zRotate = Mathf.Clamp(zRotate, -5, 5);
transform.rotation = Quaternion.Euler(0, 0, zRotate);
//rotate back its idle position(0 degrees)
// how????
}
}