【发布时间】:2016-05-07 20:38:11
【问题描述】:
我正在尝试让 3D 对象在玩家放开任何影响键时缓慢返回其原始旋转。
这是我目前所拥有的:
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);
}
}
但我没有运气。我怎样才能让它工作?
【问题讨论】: