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);
为了避免向上/向下倾斜,您可以在将其送入系统之前将方向归零
外观旋转
// 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 -90f