【问题标题】:Unity: How to rotate first person camera by dragging touch across?Unity:如何通过拖动触摸来旋转第一人称相机?
【发布时间】:2019-05-17 15:21:18
【问题描述】:

也许值得注意的是,我将手指资产用于触摸/鼠标。

好的,所以我有一个带有第一人称摄像头的炮塔,在 PC 上,当我在摄像头周围移动鼠标时,它使用鼠标 X/Y 轴。但我需要 Mobile 与轴鼠标 X/Y 一起使用触摸来拖动相机。

我需要帮助的是: 当我的手指在屏幕上拖动以移动相机的旋转而不是位置时。位置由车辆修改。

这是我用于 PC 第一人称的代码,移动鼠标:

 x += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
 y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;

 Quaternion rotation = Quaternion.Euler(y, x, 0f);

 turretHeadToMove.rotation = rotation;

如何使用触摸拖动来移动旋转?而不是鼠标?

对此有什么帮助吗?谢谢


这是当前的触摸代码

if (Input.touchCount > 0)
{
    if (Input.GetTouch(0).phase == TouchPhase.Moved)
    {
        Touch touch = Input.GetTouch(0);
        x += touch.deltaPosition.x * xSpeed * 0.02f;
        y -= touch.deltaPosition.y * ySpeed * 0.02f;

        Quaternion rotation = Quaternion.Euler(y, x, 0f);

        turretHeadToMove.rotation = rotation;
    }
}

【问题讨论】:

  • 你见过this吗?
  • @Daniel 是的,但那是 pc 鼠标,我想用触摸来拖动旋转
  • 据我所知,触摸和电脑鼠标的行为方式相同。 Input.mousePositionInput.GetTouch(0).position 应该是一样的。
  • 那么我如何将Input.GetAxis("Mouse X") 转换为使用GetTouch(0)
  • 您可以存储最后一次触摸位置,Input.GetAxis("Mouse X") 的行为应该与lastPos.x - currPos.x 类似,但我不确定,从未使用过这种GetAxis 方法。

标签: unity3d rotation touch


【解决方案1】:

对于触摸,您可以使用

Input.GetTouch(0).deltaPosition

试着用这个来摆弄一些东西:

float strength = 2;

if (Input.touchCount == 1) { 
  if (Input.GetTouch(0).phase == TouchPhase.Moved)
  {
    Vector2 touchDirection = Input.GetTouch(0).deltaPosition;
    // Update ur transform.Rotate the way u desire
    // Different depending on using 1st person, 3rd person etc.
  }
}

【讨论】:

  • 我用新的触摸代码更新了问题,但它不能正常工作,我希望它像谷歌地球一样,你用手指拖动慢慢旋转到你想要的地方跨度>
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多