我不知道这里发生了什么,但我需要一个解决办法。这是一个非常简单的任务-我有一个空的,其中包含一个电枢/身体网格,我在周围移动使用ITween,我需要身体旋转,以面对它正在移动的对象。
我的问题是,我的容器对象内部的电枢有z轴,无论出于什么原因,无论是子电枢还是更大的容器,lookAt旋转都是90度,因此对象的左侧是面向目标的。


我试过:
Vector3 relativePos = test.transform.position - transform.position;
Quaternion rotation = Quaternion.LookRotation(relativePos);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * 1f);我一直试图同时使用LookAt和iTween,但都没有用。我知道iTween正在进行旋转,因为这使得对象在z轴上旋转90度(我只需要该对象在Vector3.up轴上面向目标--其中mainModel是电枢:
iTween.RotateTo(mainModel, iTween.Hash(
"z", this.gameObject.transform.eulerAngles.x + 90,
"time", 1f,
"easetype", "easeInOutSine",
"looptype", "pingpong"
));当我在目标处用LookRotation替换时,LookRotation要么不能工作,要么面向左。
如何使LookRotation在向上轴上偏移90度?这里怎么了?
发布于 2018-10-26 19:18:35
您可以将LookRotation的结果与修改的Quaternion相乘,以抵消所需的旋转。为了获得更高的转速,您可以使用RotateTowards来设置适当的最大转速。
// Find out where we want to look
Quaternion targetRotation = Quaternion.LookRotation(test.transform.position
- transform.position);
targetRotation *= Quaternion.Euler(0f, 90f, 0f); // might need to be -90f
// Find out how far to rotate
float maxDegreesPerSecond = 90f; // This is your max speed for rotation in degrees/sec
float maxDegreesDelta = maxDegreesPerSecond * Time.deltaTime;
transform.rotation = Quaternion.RotateTowards(transform.rotation,
targetRotation,
maxDegreesDelta); 为了避免向上/向下倾斜,您可以在将方向输入LookRotation之前将其归零。
// Find out where we want to look
Vector3 targetDirection = test.transform.position - transform.position;
targetDirection = new Vector3(targetDirection.x, 0f, targetDirection.z);
Quaternion targetRotation = Quaternion.LookRotation(targetDirection);
targetRotation *= Quaternion.Euler(0f, 90f, 0f); // might need to be -90fhttps://stackoverflow.com/questions/53014742
复制相似问题