比如玩家 需要面向一个 敌人 :
1.transform.LookAt
2. Quaternion.LookRotation
3.原始的数学关系计算
/// <summary>
/// @brief turn rotation to the target position
/// </summary>
public void rotateToPosition(Vector3 pos_target)
{
float delta_x = transform.position.x - pos_target.x;
float delta_z = transform.position.z - pos_target.z + 0.01f;
//revise the angle 0-180 and 180-360
float delta = delta_z < 0 ? 0 : 180;
transform.rotation = Quaternion.Euler(transform.rotation.x,
Mathf.Atan(delta_x / delta_z) * 180.0f / Mathf.PI + delta
, transform.rotation.z);
}