// take camera's forward vector
private forward = yourCamera.transform.forward;
// erase the Y axis => vector is now only on the XZ plane rotating around Y
forward.y = 0;
// rotate the capsule so its forward vector aligns with "forward"
yourCapsule.transform.rotation = Quaternion.LookRotation(forward);
// could also do
//yourCapsule.transform.forward = forward;
1条答案
按热度按时间plicqrtu1#
Transform.rotation
返回一个Quaternion
(另请参见Wikipedia - Quaternion)-它具有不是3个而是4个组件x
、y
、z
和w
!=〉除非你确切地知道自己在做什么--几乎从来都不是这样--否则你永远不想直接接触它的任何组成部分。
不幸的是,
Transform.eulerAngles
对于您的用例来说并不真正可靠。因此,我会转而依赖
Vector3
。另请参见
Quaternion.LookRotation