【问题标题】:Lean Rotate Custom Axis with only one finger仅用一根手指倾斜旋转自定义轴
【发布时间】:2019-07-24 14:04:16
【问题描述】:

我想自己旋转我的 AR 对象,所以在一个轴上,只用一根手指。所以我使用 Lean Touch(免费版)和 Script Lean Rotate Custom Axis。 这个过程用两根手指效果很好,但我找不到自然的运动。我只希望当您将手指向右滑动时,对象会向右转,反之亦然。

我已经发现有人问过这个问题here,并测试了建议的答案,但它不起作用。如果有人已经遇到这个问题或者可以有解决方案,请提前感谢您

void OnMouseDrag()
{
    float rotationX = Input.GetAxis("Mouse X") * rotationSpeed * Mathf.Deg2Rad;
    transform.Rotate(Vector3.down, -rotationX, Space.World);
}

【问题讨论】:

  • "It doesn't work" 听起来好像它甚至无法编译。请更详细地说明“它不起作用”的含义。

标签: c# unity3d touch vuforia


【解决方案1】:

您可以尝试使用Input.GetTouch 来实现实际的触摸支持,例如

private Vector2 lastPos;

private void Update()
{
    // Handle a single touch
    if (Input.touchCount == 1)
    {
        var touch = Input.GetTouch(0);

        switch(touch.phase)
        {
            case TouchPhase.Began:
                // store the initial touch position
                lastPos = touch.position;
                break;

            case TouchPhase.Moved:
                // get the moved difference and convert it to an angle
                // using the rotationSpeed as sensibility
                var rotationX = (touch.position.x - lastPos.x) * rotationSpeed;
                transform.Rotate(Vector3.up, -rotationX, Space.World);

                lastPos = touch.position;
                break;
        }
    }
}

或者因为 Unity 还允许 GetMouseButtonDown(0) 进行第一次触摸:

private void Update()
{
    if (Input.GetMouseButtonDown(0))
    {
        lastPos = (Input.mousePosition);
    }
    else if (Input.GetMouseButton(0))
    {
        var rotationX = ((Input.mousePosition).x - lastPos.x) * rotationSpeed;
        transform.Rotate(Vector3.up, -rotationX, Space.World);

        lastPos = Input.mousePosition;
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-14
    • 1970-01-01
    • 2016-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多