【发布时间】:2018-03-01 05:35:19
【问题描述】:
目前我有一艘环绕行星飞行的宇宙飞船。看起来是这样的
我使用这个代码
public class PlayerMovement : MonoBehaviour
{
private float currentMovementSpeed = 30;
private float rotationSpeed = 80;
private Rigidbody rigid;
private void Start()
{
rigid = GetComponent<Rigidbody>();
}
private void Update()
{
// move the spaceship
rigid.MovePosition(rigid.position + transform.TransformDirection(new Vector3(0, 0, 1)) * currentMovementSpeed * Time.deltaTime);
// rotate the shaceship by pressing A or D
transform.Rotate(0, Input.GetAxis(StringCollection.INPUT_HORIZONTAL) * rotationSpeed * Time.deltaTime, 0);
}
}
所以当我按 A 时,我想将船向左倾斜
当按 D 时,我想向右倾斜船
有人知道怎么做吗?
【问题讨论】:
-
如果 A 或 D 关闭,您可以检查更新,然后应用您的旋转功能。