이런식으로 Grabbable에 옵션으로 한손과 두손관련 정보를 담은 스크립트를 할당해주면

크기를 늘릴 수 있다.

 

 

 


 

 

 

 


 

미완성

 

 

 

위의 코드는 오른손과 왼손은의 인지를 다르게 해주게 하기 위함이다.

예를들어 왼손으로는 오른손아래 손잡이를 잡지 못하게 할 수 있다.

using Oculus.Interaction;
using Oculus.Interaction.HandGrab;
using UnityEngine;
using static OVRHand;

public class HandController : MonoBehaviour
{
    [SerializeField]
    private Hand HandType = Hand.None;
    public HandGrabInteractor leftHandGrabInteractor;
    public HandGrabInteractor rightHandGrabInteractor;

    private void OnTriggerEnter(Collider other)
    {
        if (HandType == Hand.HandLeft 
            && other.GetComponent<OneGrabFreeTransformer>() != null) {

            leftHandGrabInteractor.gameObject.SetActive(false);

        }
        else if (HandType == Hand.HandRight
            && other.GetComponent<TwoGrabFreeTransformer>() != null)
        {
            rightHandGrabInteractor.gameObject.SetActive(false);
        }
    }

    private void OnTriggerExit(Collider other)
    {
        if (HandType == Hand.HandLeft
            && other.GetComponent<OneGrabFreeTransformer>() != null)
        {
            leftHandGrabInteractor.gameObject.SetActive(true);
        }
        else if (HandType == Hand.HandRight
            && other.GetComponent<TwoGrabFreeTransformer>() != null)
        {
            rightHandGrabInteractor.gameObject.SetActive(true);
        }

    }
}

 

완성이되면 왼손 오른손 각각 이미지를 로드 후 세이브 해서 손모양을 저장하고

 

손을 가져다 대면 각각 왼손과 오른손이 지정된 위치로 그랩을 할 수 있다.

'산대특 > VRAR' 카테고리의 다른 글

[VR] Locomotion(Teleport)  (0) 2024.04.23
[VR]반대손 복사와 회전 및 던지기  (0) 2024.04.19
[VR]총 잡기 - HandGun Grab  (1) 2024.04.18
Create Ghost Reticles  (0) 2024.04.18
Oculus Settings and Grab  (0) 2024.04.17

https://assetstore.unity.com/packages/3d/environments/simplepoly-city-low-poly-assets-58899

 

SimplePoly City - Low Poly Assets | 3D 주변환경 | Unity Asset Store

Elevate your workflow with the SimplePoly City - Low Poly Assets asset from VenCreations. Find this & other 주변환경 options on the Unity Asset Store.

assetstore.unity.com

 

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;
        }
    }
}

 

 

collider가 있어서 이 안으로 텔레포트 할 수 없다.

어싸인 확인

이건 엄지와 검지를 닿게 할 것인지를 결정

이제 핸드트래킹(손가락)으로도 턴을 적용 시킬 수 있다.

 

 

 

 

영상과 같이 길로만 이동할수 있따.

 

 


 

 

 

 

'산대특 > VRAR' 카테고리의 다른 글

[VR] Transformer Interaction  (0) 2024.04.23
[VR]반대손 복사와 회전 및 던지기  (0) 2024.04.19
[VR]총 잡기 - HandGun Grab  (1) 2024.04.18
Create Ghost Reticles  (0) 2024.04.18
Oculus Settings and Grab  (0) 2024.04.17

한손만 복사본을 저장했다면 이버튼을 눌러 반대손도 적용 할 수 있다.

 

 

 

 


그런데 공을 다시 잡으면 손이 저장된 위치로 가기 때문에 공이 회전한다.

이 공의 회전을 고정하기 위한 작업을 실행했다.

모든 작업들은 오른손을 했으면 왼손도 적용해주면 된다.

 

 

이제 공을 다시 잡아도 돌지 않는다.

 

 

 

이번에는 책에 적용해 보았다.

아까 설명한 오른손으로 이미지를 잡고 왼손을 복사하여 적용된 모습이고

 

생성된 Hand Grab Pose에 Box Grab Surface 컴포너트를 추가한 후

박스를 정하는데

이는 손목을 기준점으로 잡힌다.

 

그후

 

 

여기 Follow Surface를 설정하면 테스트도 해볼 수 있다.

 

 

 

중력을 키면 책이 책상에 떨어진다.

프로젝트에 있는 HandVelocityCalculator 추가 한후

인트렉터에 넣어준다.

 

주의 !

책의 y좌표보다 낮아야지 리스폰이 된다.

즉, 기존의 좌표보다 낮을 경우 리스폰이 된다.

 

 

'산대특 > VRAR' 카테고리의 다른 글

[VR] Transformer Interaction  (0) 2024.04.23
[VR] Locomotion(Teleport)  (0) 2024.04.23
[VR]총 잡기 - HandGun Grab  (1) 2024.04.18
Create Ghost Reticles  (0) 2024.04.18
Oculus Settings and Grab  (0) 2024.04.17

+ Recent posts