外观等效旋转2D

时间:2019-01-11 16:10:02

标签: c# unity3d

Quaternion targetRotation = Quaternion.LookRotation(path.lookPoints[pathIndex] - transform.position);
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, turnSpeed);
transform.Translate(Vector3.right * speed * Time.deltaTime,Space.Self)

我想用等同于2d的代码替换上面的代码,但是我在互联网上发现的所有内容似乎根本没有帮助。有什么帮助吗?

1 个答案:

答案 0 :(得分:1)

一旦知道了正面矢量,就可以使用Quaternion.FromToRotation来获得targetRotation,您需要将正面指向路径中的下一个点。

Vector3 frontVector = Vector3.right; // Set your front vector here

Quaternion targetRotation = Quaternion.FromToRotation(frontVector, 
        path.lookPoints[pathIndex] - transform.position);
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, turnSpeed);
transform.Translate(Vector3.right * speed * Time.deltaTime,Space.Self)