LoginSignup
1
1

More than 3 years have passed since last update.

Oculus Go / Quest で、コントローラーで移動できるようにする

Posted at

Oculus Go / Quest 用のアプリを作っていて、コントローラーから、前後左右に移動できるようにする時のメモです。

Oculus Quest

Oculus Integrationを導入している場合、OVRCameraRig に、次のようなスクリプトをアタッチすれば、左スティックで動くようになります。

Hoge.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Hoge : MonoBehaviour {

    private void Update()
    {
        // 前後への移動
        var v = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick).y;
        Vector3 velocity = new Vector3(0, 0, v);
        velocity = transform.TransformDirection(velocity);
        velocity *= 5f;
        transform.localPosition += velocity * Time.fixedDeltaTime;

        // 左右への方向転換
        var h = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick).x;
        transform.Rotate(0, h * 3f, 0);
    }
}

ちなみに、右スティックに割り当てたい場合は、OVRInput.Axis2D.PrimaryThumbstickOVRInput.Axis2D.SecondaryThumbstickに変えてください。

また、手を表示するためにLocalAvatarWitdhGrabを使っている場合は、スクリプトはこちらにアタッチしてください。(カメラのみが動いて、手の位置が同期されなくなるため)

Oculus Go

上記の OVRInput.Axis2D.PrimaryThumbstickOVRInput.Axis2D.PrimaryTouchpad に変えればOKです。

OVRInputについて

公式サイトに、コントローラーごとの、入力の取得方法がまとまっています。
OVRInput
コントローラーの入力を受け取って何かしたい場合は、上記を確認すると良さそうです。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1