使用 Samsung Gear-VR 从摄像头方向扫射

Strafe from Camera-look direction using Samsung Gear-VR

我在一些游戏逻辑方面遇到了一些问题。现在我有一个设置,让玩家使用带有 Gear-VR 耳机 + Gear 控制器的新三星 Galaxy S8 来探索环境。当前代码的设置是,玩家可以使用角色控制器使用他们正在看的方向向前和向后移动,并根据 'touchpad' 计算相机正在移动的方向控制器。

我有一个水平轴和垂直轴(基于控制器 'touch'),在 Vector2 中从 -1.0 到 1.0。

if (input.y > 0.0f || input.y < 0.0f || input.x > 0.0f || input.x < 0.0f) {
    Vector3 direction = new Vector3(cameraObject.transform.forward.x, 0, cameraObject.transform.forward.z);
    cC.Move(direction * walkSpeed * Time.deltaTime * input.y);
}

上面的代码通过计算摄像机注视的方向并'towards'移动'towards'来向前和向后平移玩家,但我还需要'strafe'向左和向右移动似乎无法弄清楚。

我以前没有使用过控制器输入,但我假设 input.x 是 left/right,input.y 是 forward/back,对吗?

我相信你的角色只是向前和向后移动,因为你只使用 cameraObjecttransform.forawrd 矢量,它只在 z 方向上,没有 x 分量。

试试这个(使用 transform.forwardtransform.right):

cC.Move((cameraObject.transform.forward * input.y + cameraObject.transform.right * input.x) * walkSpeed * Time.deltaTime)