LookRotation() z轴指向正确但是z的旋转不对
项目中碰到一个问题,用LookRotation(dir)来获取并设置飞镖的初始化状态,但是很奇怪,z轴指向正确,但是旋转不对。在新建的项目试了又没有问题,最后发现离了大谱,这3D项目场景默认z轴向上,正常人哪见过这等场面啊。
因为项目中很多旋转是写死的,不好动场景,只能从LookRotation(dir)下手。LookRotation(dir)默认是y轴方向作为上方向,在我的项目中要换为Z轴向上。
//
// 摘要:
// Creates a rotation with the specified forward and upwards directions.
//
// 参数:
// forward:
// The direction to look in.
//
// upwards:
// The vector that defines in which direction up is.
[ExcludeFromDocs]
public static Quaternion LookRotation(Vector3 forward)
{
return LookRotation(forward, Vector3.up);
}
//上方向为全局坐标系的Z轴,使物体的正Y轴指向目标方向
Quaternion.LookRotation(dir, Vector3.forward);