Create Locomotion Interactions
VR/Oculus Integration 2023. 12. 5. 15:49
CameraRig에 Rigidbody, CapsuleCollider 부착
Simple Capsule with stick movement 컴포넌트 CameraRig에 추가
HandPrefab추가 기본 형 만들기
OVRHands추가
LocomotionHandInteractorGroup 추가
Finger Feature State Provider추가
오른손에도 적용
Provider에 넣어주기
Locomotion 빈 오브젝트 만들고 PlayerLocomotor 추가
Handle에 넣어주기
Teleport Interactable 추가
TurnerInteractor의 Transformer 필드에 OVRInteraction넣어주기
Plane 추가
Controller 추가
LocomotionControllerInteractorGroup추가
Handler 필드에 Locomotion넣어주기
왼손은 필요 없음
빈오브젝트 Controller Features만들기
Axis2D에 넣어주기
브로드캐스터에서 턴 지우기
왼손 컨트롤 안움직이면 speed 확인 3.5
Simple 어쩌구에서 이동하는거 턴하는거 컨트롤러 인풋 받아서 처리 함
using System.Collections;
using System.Collections.Generic;
using System;
using UnityEngine;
public class SimpleCapsuleWithStickMovement : MonoBehaviour
{
public bool EnableLinearMovement = true;
public bool EnableRotation = true;
public bool HMDRotatesPlayer = true;
public bool RotationEitherThumbstick = false;
public float RotationAngle = 45.0f;
public float Speed = 0.0f;
public OVRCameraRig CameraRig;
private bool ReadyToSnapTurn;
private Rigidbody _rigidbody;
public event Action CameraUpdated;
public event Action PreCharacterMove;
private void Awake()
{
_rigidbody = GetComponent<Rigidbody>();
if (CameraRig == null) CameraRig = GetComponentInChildren<OVRCameraRig>();
}
void Start()
{
}
private void FixedUpdate()
{
if (CameraUpdated != null) CameraUpdated();
if (PreCharacterMove != null) PreCharacterMove();
if (HMDRotatesPlayer) RotatePlayerToHMD();
if (EnableLinearMovement) StickMovement();
if (EnableRotation) SnapTurn();
}
void RotatePlayerToHMD()
{
Transform root = CameraRig.trackingSpace;
Transform centerEye = CameraRig.centerEyeAnchor;
Vector3 prevPos = root.position;
Quaternion prevRot = root.rotation;
transform.rotation = Quaternion.Euler(0.0f, centerEye.rotation.eulerAngles.y, 0.0f);
root.position = prevPos;
root.rotation = prevRot;
}
void StickMovement()
{
Quaternion ort = CameraRig.centerEyeAnchor.rotation;
Vector3 ortEuler = ort.eulerAngles;
ortEuler.z = ortEuler.x = 0f;
ort = Quaternion.Euler(ortEuler);
Vector3 moveDir = Vector3.zero;
Vector2 primaryAxis = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick);
moveDir += ort * (primaryAxis.x * Vector3.right);
moveDir += ort * (primaryAxis.y * Vector3.forward);
//_rigidbody.MovePosition(_rigidbody.transform.position + moveDir * Speed * Time.fixedDeltaTime);
_rigidbody.MovePosition(_rigidbody.position + moveDir * Speed * Time.fixedDeltaTime);
}
void SnapTurn()
{
if (OVRInput.Get(OVRInput.Button.SecondaryThumbstickLeft) ||
(RotationEitherThumbstick && OVRInput.Get(OVRInput.Button.PrimaryThumbstickLeft)))
{
if (ReadyToSnapTurn)
{
ReadyToSnapTurn = false;
transform.RotateAround(CameraRig.centerEyeAnchor.position, Vector3.up, -RotationAngle);
}
}
else if (OVRInput.Get(OVRInput.Button.SecondaryThumbstickRight) ||
(RotationEitherThumbstick && OVRInput.Get(OVRInput.Button.PrimaryThumbstickRight)))
{
if (ReadyToSnapTurn)
{
ReadyToSnapTurn = false;
transform.RotateAround(CameraRig.centerEyeAnchor.position, Vector3.up, RotationAngle);
}
}
else
{
ReadyToSnapTurn = true;
}
}
}
'VR > Oculus Integration' 카테고리의 다른 글
Create a Flat UI (0) | 2023.12.06 |
---|---|
Create Poke Interactions (0) | 2023.12.06 |
Meta Quest Developer Hub for Windows (0) | 2023.11.22 |
Meta Avatars SDK (0) | 2023.11.22 |
스테레오 랜더링모드 오큘러스 셋팅 (0) | 2023.11.22 |