【发布时间】:2020-05-12 03:47:37
【问题描述】:
我的相机正在寻找一个对象A。当我向上或向下移动鼠标或滚动鼠标滚轮时,相机会靠近或远离A。
//frontal movement
Vector3 frontal = transform.forward *
(Input.GetAxis("Mouse Y") + Input.mouseScrollDelta.y) *
0.3f;
//distance from the camera to the object
if(Vector3.Distance(A.position, transform.position + frontal) > minDistance)
transform.position += frontal;
重点是:我不希望相机离A 太近,所以我定义了一个浮点数minDistance 来说明相机与物体之间的最小距离。
问题:我的代码简单地说:“如果最终位置比minDistance 更近,请不要移动”。这不是我想要的行为。如果最终位置比minDist 更近,我希望它移动到距离正好为minDist 的点。我该怎么做?
【问题讨论】:
标签: c# unity3d camera game-physics