我正在根據(jù)屏幕動態(tài)創(chuàng)建網(wǎng)格對象。因此包含網(wǎng)格對象的對象總是大小相同,但網(wǎng)格對象具有不同的形狀和大小。我想讓你看到我的照片并理解它。事實上,藍色區(qū)域是透明的。我目前正在使用移動相機在地板上拍攝 Ray,我想將物體放置在 Ray 擊中的位置。但這似乎需要大量的計算。我認為我們應該首先使用對象中心坐標以外的其他坐標。而且我認為我們應該將物體放置在碰撞點上方一點點。網(wǎng)格對象的一半大小,所以我嘗試了這個,但我失敗了。我該如何解決這個問題?下面是我的源代碼。Vector3 hitPositon = hit.Pose.position;Vector3 meshObjectCenter = ObjectPrefab.GetComponent<Renderer>().bounds.center;Vector3 meshObjectSize = ObjectPrefab.GetComponent<Renderer>().bounds.size;Vector3 CenterPointRevision = meshObjectCenter - hitPositon;Vector3 YAxisRevision = new Vector3(0, meshObjectSize.y / 2, 0); Vector3 NewPoint = ARObjectPrefab.transform.position - CenterPointRevision + YAxisRevision; ObjectPrefab.transform.position = NewPoint;object就是這種格式,上圖看起來是成功但失敗的情況。
1 回答

達令說
TA貢獻1821條經(jīng)驗 獲得超6個贊
該位置只是命中位置減去中心偏移量加上 y 軸偏移量:
Vector3 hitPositon = hit.Pose.position;
Vector3 meshObjectCenter = ObjectPrefab.GetComponent<Renderer>().bounds.center;
Vector3 meshObjectSize = ObjectPrefab.GetComponent<Renderer>().bounds.size;
Vector3 YAxisRevision = new Vector3(0, meshObjectSize.y / 2, 0);
ObjectPrefab.transform.position = hitPositon - meshObjectCenter + YAxisRevision;
- 1 回答
- 0 關注
- 93 瀏覽
添加回答
舉報
0/150
提交
取消