Giant vs Human 팀프로젝트 개발일지

[Giant vs Human 팀프로젝트/Meta Quest, VR, Oculus] Haptic feedback(진동)

다모아 2023. 11. 22. 22:52

해야할 것 : GameObject를 만지면 진동이 오게 만든다.

 

만들기 위해 준비할 것

 

1. GameObject Cube를 만들어준다.

 

2. Cube에다가 Haptic 시스템을 적용할 Scripts를 넣어준다

.3. Scripts 작성

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

public class TestHaptic : MonoBehaviour
{
    
    public void OnSelect()
    {
        float primaryIndexTrigger = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger);
        float primaryHandTrigger = OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger);
        float secondIndexTrigger = OVRInput.Get(OVRInput.Axis1D.SecondaryIndexTrigger);
        float secondHandTrigger = OVRInput.Get(OVRInput.Axis1D.SecondaryHandTrigger);

        //왼손
        if (primaryHandTrigger > 0)
        {
            OVRInput.SetControllerVibration(1, 1, OVRInput.Controller.LTouch);
        }
        //왼손
        else if (primaryIndexTrigger > 0)
        {
            OVRInput.SetControllerVibration(1, 1, OVRInput.Controller.LTouch);
        }
        //오른손
        else if (secondHandTrigger > 0)
        {
            OVRInput.SetControllerVibration(1, 1, OVRInput.Controller.RTouch);
        }
        //오른손
        else if (secondIndexTrigger > 0)
        {
            OVRInput.SetControllerVibration(1, 1, OVRInput.Controller.RTouch);
        }
    }
}

OnSelect 상태고 Cube의 Pointable Unity Event Wrapper를 사용하여 When Select 상태일 때 OnSelect() 메서드를 사용하게 했음.

 

이러면 Cube를 집으면 왼손, 오른손의 float 값을 받아 어떤 트리거가 Cube를 집었는지 확인하고 큐브를 집었을 때 진동을 오게함

 

----

하지만 이 OVRInput.SetControllerVibration 기능은 진동을 몇 초 울리게하고 그런 기능이 탑재되어있지 않음.

수정 방안이 필요