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.PrimaryThumbstick
をOVRInput.Axis2D.SecondaryThumbstick
に変えてください。
また、手を表示するためにLocalAvatarWitdhGrab
を使っている場合は、スクリプトはこちらにアタッチしてください。(カメラのみが動いて、手の位置が同期されなくなるため)
Oculus Go
上記の OVRInput.Axis2D.PrimaryThumbstick
を OVRInput.Axis2D.PrimaryTouchpad
に変えればOKです。
OVRInputについて
公式サイトに、コントローラーごとの、入力の取得方法がまとまっています。
OVRInput
コントローラーの入力を受け取って何かしたい場合は、上記を確認すると良さそうです。