Unity-半球形的Quaternion.Slerp [英] Unity - Quaternion.Slerp in a semisphere

查看:243
本文介绍了Unity-半球形的Quaternion.Slerp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个轨道照相机正在半弯曲地移动着.我有一架飞机,上面还有其他物体.在场景的中间,有一个空的物体,我正在将其用作相机的支点,所有物体都按预期工作.我说平动层是因为我不想降落"在飞机下面,实际上我有控制权来避免它.

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.

现在我想看一个物体,然后朝那个方向轻轻旋转.为此,我正在使用以下代码:

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链接1 img链接2

推荐答案

除非您确实要将向上方向指定为"Vector3.right",否则只需删除第二个参数即可:

unless you really want to specify the upward direction as "Vector3.right", just remove the second parameter:

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);
}

这篇关于Unity-半球形的Quaternion.Slerp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆