【问题标题】:AR Object Drifting/Flying Away Issue Unity AR FoundationAR Object Drifting/Flying Away 问题 Unity AR Foundation
【发布时间】:2020-09-15 10:13:13
【问题描述】:

我是 AR 开发的新手,很抱歉这个菜鸟问题。我在相机前生成了一个 AR 对象,该对象生成良好,但有时,该对象开始向随机方向漂移。谁能帮我解决这个问题?我已经搜索了很长时间;我找不到修复程序。

对象生成

prefabInstance = Instantiate(placeObject);
GetComponent<ARSessionOrigin>().MakeContentAppearAt(prefabInstance.transform, new Vector3(0, -0.76f, 3.35f), Quaternion.identity);

我想摇晃将物体粉碎。在对象被分割后,我将它们重新放置在不同的区域。我只重定位父对象,而碎片在对象的子对象中。

搬迁代码

int temp = UnityEngine.Random.Range(0, ReferenceSpawnPoint.Length); 
gObject.transform.position = new Vector3(ReferenceSpawnPoint[temp].position.x, ReferenceSpawnPoint[temp].position.y, ReferenceSpawnPoint[temp].position.z); 
float y = UnityEngine.Random.Range(0, 360); 
float z = UnityEngine.Random.Range(-10, 10); 
gObject.transform.rotation = Quaternion.Euler(0, y, 0);

我还附上了视频的链接;请看一下,你就会明白我在说什么video link。为方便起见,请从 0:30 秒标记开始。

您的帮助将不胜感激。

有时我也会出现黑屏;这是否意味着 AR Session 没有初始化?

插件/工具版本:

  • 统一:2019.2.7f2
  • XR ARCore:3.1.3
  • XR AR 基础:3.1.3
  • XR ARKit:3.1.3
  • XR 旧版输入助手:2.1.4

【问题讨论】:

    标签: c# unity3d augmented-reality arkit arcore


    【解决方案1】:

    您放置对象的方式似乎是错误的。更好的方法是使用光线投射并将 3D 对象放置在用户输入定义的某个位置,例如触摸屏幕。

    AR Foundation 示例场景有一个名为 PlaceOnPlane.cs 的脚本,它展示了如何检测用户何时触摸屏幕,然后从屏幕向世界投射光线以激活游戏对象:

    if (Input.touchCount == 1) {
        if (m_RaycastManager.Raycast(Input.GetTouch(0).position, s_Hits, TrackableType.PlaneWithinPolygon))
            {
                // Raycast hits are sorted by distance, so the first one
                // will be the closest hit.
                var hitPose = s_Hits[0].pose;
    
                if (spawnedObject == null)
                {
                    spawnedObject = Instantiate(m_PlacedPrefab, hitPose.position, hitPose.rotation);
                }
            }
    

    在“真实世界”位置(例如 hitPose.position)实例化模型后,您应该不会再看到它漂移了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-06-15
      • 1970-01-01
      • 1970-01-01
      • 2023-01-31
      • 2022-10-03
      • 2023-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多