【问题标题】:ARKit - How to move object along the recognised surface?ARKit - 如何沿着识别的表面移动物体?
【发布时间】:2018-01-03 02:32:25
【问题描述】:

如何使 3D 对象(汽车)沿 ARKit(Unity、C#)识别的表面移动?

因此,我可以使用 UI 来操纵汽车,而不是手指敲击,而汽车将使用 ARKit 识别的表面进行移动并与它发生碰撞,以防出现任何刚体效应。

是否可以让它也与其他表面(例如墙壁)发生碰撞?

【问题讨论】:

    标签: c# unity3d unity5 arkit


    【解决方案1】:

    这样的东西可以让你点击你的对象并拖动它沿着一个表面移动。关于碰撞等 - 确保您的对象具有适当的碰撞器和刚体。 ARKit 目前只提供水平面,所以不知道如何处理墙壁碰撞...

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class DragAlongSurface : MonoBehaviour {
    
      private bool holding;
    
      void Start () {
        holding = false;
      }
    
      void Update() {
    
        if (holding) {
          Move();
        }
    
        // One finger
        if (Input.touchCount == 1) {
    
          // Tap on Object
          if (Input.GetTouch(0).phase == TouchPhase.Began ) {
            Ray ray = Camera.main.ScreenPointToRay (Input.GetTouch(0).position);
            RaycastHit hit;
    
            if (Physics.Raycast (ray, out hit, 100f)) {
              if (hit.transform == transform) {
                holding = true;
              }
            }
          }
    
          // Release 
          if (Input.GetTouch(0).phase == TouchPhase.Ended) {
            holding = false;
          } 
        }
      }
    
      void Move(){
       RaycastHit hit;
       Ray ray = Camera.main.ScreenPointToRay (Input.GetTouch (0).position);
       // The GameObject this script attached should be on layer "Surface"
       if(Physics.Raycast(ray, out hit, 30.0f, LayerMask.GetMask("Surface"))) {
         transform.position = new Vector3(hit.point.x,
                                          transform.position.y,
                                          hit.point.z);
        }
      }    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-12
      • 2014-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-28
      • 1970-01-01
      相关资源
      最近更新 更多