Я пытаюсь получить 3D-объект, чтобы медленно возвращаться к его первоначальному вращению, когда игрок отпускает любой из влияющих клавиш.Unity3d вернуться к исходному ротации
Это то, что я до сих пор:
using UnityEngine;
using System.Collections;
public class ShipController : MonoBehaviour {
public float turnRate;
public Transform baseOrientation;
private Vector3 worldAxis, worldAxisRelative;
private Rigidbody rb;
void Start() {
rb = GetComponent<Rigidbody>();
worldAxis = new Vector3 (0, 0, 0);
worldAxisRelative = transform.TransformDirection (worldAxis);
}
void Update() {
}
void FixedUpdate()
{
if (Input.GetKey (KeyCode.LeftArrow)) {
rb.transform.Rotate (Vector3.down * turnRate * Time.deltaTime);
}
if (Input.GetKey (KeyCode.RightArrow)) {
rb.transform.Rotate (Vector3.up * turnRate * Time.deltaTime);
}
if (Input.GetKey (KeyCode.UpArrow)) {
rb.transform.Rotate (Vector3.left * turnRate * Time.deltaTime);
}
if (Input.GetKey (KeyCode.DownArrow)) {
rb.transform.Rotate (Vector3.right * turnRate * Time.deltaTime);
}
axisAlignRot = Quaternion.FromToRotation (worldAxisRelative, worldAxis) ;
rb.transform.rotation = Quaternion.Slerp(rb.transform.rotation, axisAlignRot * transform.rotation, 1.0f * Time.deltaTime);
}
}
Но я не имею никакой удачи с ней. Как я могу заставить это работать?