基于坐标放置对象,而不是Unity中的中心坐标

http://img1.mukewang.com/63a6590300013c1917690812.jpg

我正在根据屏幕动态创建网格对象。

因此包含网格对象的对象总是大小相同,但网格对象具有不同的形状和大小。

我想让你看到我的照片并理解它。事实上,蓝色区域是透明的。

我目前正在使用移动相机在地板上拍摄 Ray,我想将物体放置在 Ray 击中的位置。

http://img3.mukewang.com/63a659120001cb2610440884.jpg

但这似乎需要大量的计算。


我认为我们应该首先使用对象中心坐标以外的其他坐标。而且我认为我们应该将物体放置在碰撞点上方一点点。网格对象的一半大小,


所以我尝试了这个,但我失败了。我该如何解决这个问题?


下面是我的源代码。


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;

http://img4.mukewang.com/63a6591f00018da304570475.jpg

object就是这种格式,上图看起来是成功但失败的情况。



烙印99
浏览 72回答 1
1回答

达令说

该位置只是命中位置减去中心偏移量加上 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;
打开App,查看更多内容
随时随地看视频慕课网APP