https://assetstore.unity.com/packages/3d/props/weapons/katana-sword-free-143768

 

Katana Sword Free | 3D 무기 | Unity Asset Store

Elevate your workflow with the Katana Sword Free asset from Imagine Emotion. Find this & other 무기 options on the Unity Asset Store.

assetstore.unity.com

 

https://github.com/DavidArayan/ezy-slice

 

GitHub - DavidArayan/ezy-slice: An open source mesh slicer framework for Unity3D Game Engine. Written in C#.

An open source mesh slicer framework for Unity3D Game Engine. Written in C#. - DavidArayan/ezy-slice

github.com

 

using UnityEngine;

public class HalfExtentsVisualizer : MonoBehaviour
{
    public Vector3 halfExtents = new Vector3(1, 1, 1);
    public Color boxColor = Color.blue;  // 상자의 색깔을 설정합니다.
    public bool useWireframe = false;    // 상자를 와이어프레임으로 그릴지 여부를 결정합니다.

    void OnDrawGizmos()
    {
        // Gizmo 색상을 설정합니다.
        Gizmos.color = boxColor;

        // 오브젝트의 Collider로부터 중심 위치를 얻습니다.
        Collider collider = GetComponent<Collider>();
        Vector3 center = collider != null ? collider.bounds.center : transform.position;

        // Gizmo의 변환 행렬을 설정합니다. 오브젝트의 회전은 반영하지만, 스케일은 1로 고정합니다.
        Gizmos.matrix = Matrix4x4.TRS(center, transform.rotation, Vector3.one);

        // 상자를 그립니다. useWireframe 값에 따라 와이어프레임 또는 솔리드 상자를 그립니다.
        if (useWireframe)
        {
            Gizmos.DrawWireCube(Vector3.zero, 2.0f * halfExtents);  // 와이어프레임 상자를 그립니다.
        }
        else
        {
            Gizmos.DrawCube(Vector3.zero, 2.0f * halfExtents);  // 솔리드 상자를 그립니다.
        }
    }
}
using System.Collections;
using System.Collections.Generic;
using EzySlice;
using UnityEngine;

public class Slicer : MonoBehaviour
{
    public Material afterSliceMaterial;
    public LayerMask sliceMask;

    public bool isTouch = false;
    private void Update()
    {
        if (isTouch) {
            Slice();
        }
        //if (Input.GetKeyDown(KeyCode.Space))
        //{
        //    Slice();
        //}
    }

    public void Slice()
    {
        Collider[] objectsToSlice = Physics.OverlapBox(transform.position, new Vector3(2.08f, 0.45f, 1.33f),
            transform.rotation, sliceMask);

        Debug.LogFormat("objectsToSlice.Length: {0}", objectsToSlice.Length);

        foreach (Collider col in objectsToSlice)
        {
            SlicedHull slicedObject = SliceObject(col.gameObject);

            Debug.LogFormat("slicedObject: {0}", slicedObject);

            var upperHullGo = slicedObject.CreateUpperHull(col.gameObject, afterSliceMaterial);
            var lowerHullGo = slicedObject.CreateLowerHull(col.gameObject, afterSliceMaterial);

            Debug.LogFormat("upperHullGo: {0}", upperHullGo);
            Debug.LogFormat("lowerHullGo: {0}", lowerHullGo);

            upperHullGo.transform.position = col.transform.position;
            lowerHullGo.transform.position = col.transform.position;

            var velocity = col.GetComponent<Rigidbody>().velocity;

            ApplyPhysical(upperHullGo, velocity);
            ApplyPhysical(lowerHullGo, velocity);
            Destroy(col.gameObject);
        }
    }

    

    private void ApplyPhysical(GameObject go, Vector3 velocity)
    {
        go.AddComponent<MeshCollider>().convex = true;
        var rbody = go.AddComponent<Rigidbody>();
        rbody.velocity = -velocity;

        int randX = UnityEngine.Random.Range(0, 3);
        int randY = UnityEngine.Random.Range(0, 3);
        int randZ = UnityEngine.Random.Range(0, 3);

        rbody.AddForce(1.5f * new Vector3(randX, randY, randZ), ForceMode.Impulse);
    }

    private SlicedHull SliceObject(GameObject go)
    {
        return go.Slice(transform.position, transform.up, afterSliceMaterial);
    }
}

 

 

위에 두개는 테스트 씬에서 플레인과 큐브를 만들고 되는지 확인 후 프리팹으로 뽑아와서 부착하였다.

 

이런식으로 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

+ Recent posts