【发布时间】:2021-12-27 05:38:06
【问题描述】:
float speed = 20.0f;
float rSpeed = 200.0f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float xValue = Input.GetAxis("Horizontal");
float zValue = Input.GetAxis("Vertical");
float yValue = 0;
Vector3 movementDir = new Vector3(xValue,yValue,zValue);
movementDir.Normalize();
transform.Translate(movementDir * speed * Time.deltaTime, Space.World);
if (movementDir != Vector3.zero)
{
Quaternion toRotation = Quaternion.LookRotation(movementDir, Vector3.up);
transform.rotation = Quaternion.RotateTowards(transform.rotation, toRotation, rSpeed * Time.deltaTime);
}
代码应允许移动并沿移动方向转动。它按预期进行,但我的对象需要在当前正在执行的操作之上旋转 90 度。我一直在摆弄一些不同的东西,但似乎无法完全理解。
【问题讨论】:
标签: c# unity3d rotation quaternions