【发布时间】:2019-07-10 13:12:40
【问题描述】:
场景:
您好,我正在尝试使用鼠标控制沿 X 和 Z 轴的孔,但不希望孔移动到鼠标位置
平面 m_Plane;
private Vector3 newmousepos;
void Start()
{
m_Plane = new Plane(Vector3.up, transform.position);
}
void Update()
{
if (Input.GetMouseButton(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
float enter = 0.0f;
if (m_Plane.Raycast(ray, out enter))
{
//Get the point that is clicked
Vector3 hitPoint = ray.GetPoint(enter);
transform.position =
Vector3.Lerp(transform.position,hitPoint,Time.deltaTime*5f);
}
}
【问题讨论】:
-
你说你不希望它移动到鼠标上,那你到底需要它做什么?
-
我猜你希望它以与鼠标相同的模式移动?所以如果鼠标移动 x+5 孔应该移动 x+5?
-
你不需要光线投射。而是使用 Input.GetAxis
-
看代码,我觉得我的猜测不正确..?我认为 OP 的 lerp 有问题?由于 lerp 操作不正确,它可能会立即传送到他的位置。
-
我的意思是,当指针在场景中的随机位置时,我只想用鼠标控制孔,但我不知道如何避免孔移动到鼠标位置跨度>
标签: c# unity3d axis mouse-position