【问题标题】:Moving camera toward a particular object in unity vuforia在统一 vuforia 中将相机移向特定对象
【发布时间】:2019-09-17 17:51:27
【问题描述】:

我正在制作一个 ar 太阳系应用程序,我现在可以毫无问题地增强整个太阳系,但我想要为用户提供一个菜单,以便他可以从菜单中选择行星,当他选择相机而不是显示所有都靠近特定行星,比如木星,因此用户可以一次查看并专注于一个物体......所以基本上我想将相机移动到离静止不显示的特定行星很近的地方

【问题讨论】:

    标签: unity3d vuforia


    【解决方案1】:

    你能不能将相机移向特定行星并增加其他行星与所选行星的距离?

    伪代码: 假设你的行星分散在 x 轴上

    user clicks on the planet
      move camera towards planet
      foreach planet in planets
        dir = (selectedPlanet.transform.position - planet.transform.position).normalized
        if(dir < 0)
          //means the planet is to the left of selected planet
          planet.transform.position.x -= 10;
        else
          // planet is to the right of selected planet
          planet.transform.position.x += 10;  
    
    

    我没有在使用 unity3d 的 PC 上,所以提前为拼写错误道歉。

    【讨论】:

      【解决方案2】:

      我建议您使用 AR 来缩放和移动行星而不是相机。

      保持相机不变,但当单击行星时,缩放行星(或多个行星)对象以使它们更接近用户的视野。

      您可以使用动画师轻松做到这一点。

      【讨论】:

        【解决方案3】:

        AR 摄像机无法移动,因为您可以控制它,因此位置和旋转取决于现实世界空间,而不是游戏视图。因此,与其尝试移动相机(这是不可能的),不如尝试让行星更靠近相机。也就是说,使用相机的位置作为参考,因此您可以轻松地将每个行星靠近相机。 Transform.LookAt() 和 Vector3.MoveTowards() 可以在这里使用

        void Update()
        {
           planet1.transform.LookAt(ARCam.transform); // this is so that the planet will rotate towards the camera and then using Vector3.MoveTowards() it will move towards the camera.
        }
        
        void Update()
            {
        
                planet1.transform.position = Vector3.MoveTowards(planet1.transform.position, ARCam.transform.position, speed*Time.deltaTime);
            }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-07-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多