Skip to content

Instantly share code, notes, and snippets.

@nkjzm
Created June 17, 2019 10:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nkjzm/179f477a1de4949a2d08486caebdb55c to your computer and use it in GitHub Desktop.
Save nkjzm/179f477a1de4949a2d08486caebdb55c to your computer and use it in GitHub Desktop.
Oculus Questで空間を自由に移動するデバッグ用スクリプト
using UnityEngine;
public class DebugMover : MonoBehaviour
{
[SerializeField]
Transform Head = null;
const float Angle = 30f;
const float DashSpeed = 5f;
const float SlowSpeed = 0.2f;
void Reset()
{
Head = GetComponentInChildren<OVRCameraRig>().transform.Find("TrackingSpace/CenterEyeAnchor");
}
float Scale
{
get
{
return IsPressTrigger ? DashSpeed : IsPressGrip ? SlowSpeed : 1f;
}
}
bool IsPressTrigger
{
get
{
return Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)
|| OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger) || OVRInput.Get(OVRInput.Button.SecondaryIndexTrigger);
}
}
bool IsPressGrip
{
get
{
return Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.LeftAlt)
|| OVRInput.Get(OVRInput.Button.PrimaryHandTrigger) || OVRInput.Get(OVRInput.Button.SecondaryHandTrigger);
}
}
void Update()
{
// Forward move
if (Input.GetKey(KeyCode.W) || OVRInput.Get(OVRInput.Button.PrimaryThumbstickUp) || OVRInput.Get(OVRInput.Button.SecondaryThumbstickUp))
{
var forward = Head.forward;
forward.y = 0;
transform.position += forward.normalized * Time.deltaTime * Scale;
}
// Back move
if (Input.GetKey(KeyCode.S) || OVRInput.Get(OVRInput.Button.PrimaryThumbstickDown) || OVRInput.Get(OVRInput.Button.SecondaryThumbstickDown))
{
var forward = Head.forward;
forward.y = 0;
transform.position -= forward.normalized * Time.deltaTime * Scale;
}
// Left rotate
if (Input.GetKeyDown(KeyCode.A) || OVRInput.GetDown(OVRInput.Button.PrimaryThumbstickLeft) || OVRInput.GetDown(OVRInput.Button.SecondaryThumbstickLeft))
{
transform.Rotate(0, -Angle, 0);
}
// Right rotate
if (Input.GetKeyDown(KeyCode.D) || OVRInput.GetDown(OVRInput.Button.PrimaryThumbstickRight) || OVRInput.GetDown(OVRInput.Button.SecondaryThumbstickRight))
{
transform.Rotate(0, Angle, 0);
}
// Up move
if (Input.GetKeyDown(KeyCode.K) || OVRInput.GetDown(OVRInput.Button.Four) || OVRInput.GetDown(OVRInput.Button.Two))
{
transform.position += Vector3.up * Scale;
}
// Down move
if (Input.GetKeyDown(KeyCode.J) || OVRInput.GetDown(OVRInput.Button.Three) || OVRInput.GetDown(OVRInput.Button.One))
{
transform.position -= Vector3.up * Scale;
}
}
}
@nkjzm
Copy link
Author

nkjzm commented Jun 17, 2019

使い方は以下を参照してください。CC0です。

Oculus Questで空間を自由に移動するデバッグ用スクリプト - Qiita
https://qiita.com/nkjzm/items/72ff0406e02c1cc7075c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment