简体   繁体   English

Unity - Quaternion.Slerp半球形

[英]Unity - Quaternion.Slerp in a semisphere

i have a orbit camera who's moving on a semishpere. 我有一个正在移动半圆形的轨道摄像机。 I have a plane with some other objects over it. 我有一架飞机上面有一些其他物体。 In the middle of the scene there is an empty object that i'm using as a pivot for my camera,all is working as intended. 在场景的中间有一个空物体,我用它作为我的相机的枢轴,一切都按预期工作。 I say sempisphere because i do not want to go "under" the plane, infact i have a control to avoid it. 我说sempisphere因为我不想去“飞机下”,事实上我有一个控制来避免它。

Now i want to look at an object and smmothly rotate in that direction. 现在我想看一个物体,并朝那个方向旋转。 To do so i'm using this code: 为此我正在使用此代码:

void Update () {

         // Smoothly rotates towards target 
         Vector3 targetPoint = myobj.transform.position;
         Quaternion targetRotation = Quaternion.LookRotation(targetPoint - transform.position, Vector3.right);
         transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * 2f);

     }

img link 1 img link 2 img link 1 img link 2

unless you really want to specify the upward direction as "Vector3.right", just remove the second parameter: 除非您确实要将向上方向指定为“Vector3.right”,否则只需删除第二个参数:

void Update()
{
    // Smoothly rotates towards target 
    Vector3 targetPoint = myobj.transform.position;
    Quaternion targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
    transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * 2f);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM