【发布时间】:2017-08-01 11:12:24
【问题描述】:
this is the 3d model i wanted to connect another model like this to its silver connectors on top side and also another model to right side(so do help me to snap it)我想知道如何在运行时将两个 3D 对象对齐。即在“播放”期间,用户必须能够向上、向下、向左、向右拖动以将一个对象与另一个对象对齐。例如“乐高”,即。一个 3D 对象应该捕捉到另一个 3D 对象。我将如何实现这一目标?
这是我用于拖动的代码:
using System.Collections;
using UnityEngine;
public class drag : MonoBehaviour {
Vector3 dist;
float posX;
float PosY;
void OnMouseDown()
{
dist = Camera.main.WorldToScreenPoint(transform.position);
posX = Input.mousePosition.x - dist.x;
PosY = Input.mousePosition.y - dist.y;
}
void OnMouseDrag()
{
Vector3 curPos = new Vector3(Input.mousePosition.x - posX, Input.mousePosition.y - PosY, dist.z);
Vector3 worldPos = Camera.main.ScreenToWorldPoint(curPos);
transform.position = worldPos;
}
}
【问题讨论】:
-
取决于您想如何将它们对齐。在特定关节处连接它们?它们的位置是否完全相同?
-
谷歌的捕捉逻辑?尝试弄清楚如何让对象对齐(可能是 x 和 z 阈值)
-
@lan H. 我已编辑,请务必查看。我想将另一个模型连接到其连接器的顶部,并将另一个模型连接到连接器的右侧。请帮忙
-
@bi0phaz3 是的,thanku.but 抱歉,我已经冲浪了一周了。让一切顺利
标签: c# unity3d unity5 mesh-collider