탁구채로 탁구공 튕기기

VR/Oculus Integration 2023. 12. 22. 18:21
반응형

 https://youtube.com/playlist?list=PLTFRwWXfOIYB9hru6EjeVS0E-4jNiOuQQ&si=zoJ3NoYX6YrGnpg1


 
 
Racket구조 

 
 

Racket

 

Visuals

 
 

Mesh

 

Handle

 

Handle

 

Hand Grab Interactable

 
 

Hand Grab Pose

 
 
 
 
 


 
Ball 구조 

 
 

Visuals
Mesh (Ball)
Ball

 
 
 

Mesh/Sphere

 
 

물리 메터리얼

 

물리 메터리얼
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Ball : MonoBehaviour
{
    public float gravity = -9.8f;
    void Start()
    {
        // 중력 크기 조절 예시 (Y축 방향의 중력)
        Vector3 customGravity = new Vector3(0f, gravity, 0f); // 중력 크기 및 방향 설정
        Physics.gravity = customGravity; // 중력 크기 적용

    }

}

 

Hand Grab Interactable

 
 
 


 
터널링 방지를 위한 물리 콜라이더 

 
 
물리 메터리얼 

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

public class PhysicsCollider : MonoBehaviour
{
    private Rigidbody rBody;
    [SerializeField] private Transform target;

    private Vector3 previousPosition;
    private Quaternion previousRotation;

    void Start()
    {
        this.rBody = this.GetComponent<Rigidbody>();
        previousPosition = target.position;
        previousRotation = target.rotation;
    }

    private void FixedUpdate()
    {
        if (target != null)
        {
            // 현재 위치 및 회전을 저장합니다.
            Vector3 currentPosition = target.position;
            Quaternion currentRotation = target.rotation;

            // 이전 위치 및 회전과 현재 위치 및 회전 간의 차이를 계산합니다.
            Vector3 positionDelta = currentPosition - previousPosition;
            Quaternion rotationDelta = currentRotation * Quaternion.Inverse(previousRotation);

            // 이전 위치와 현재 위치 간의 거리를 계산합니다.
            float distance = Vector3.Distance(previousPosition, currentPosition);

            // 거리가 일정 값 이상인 경우에만 보간을 적용합니다.
            if (distance > 0.001f)
            {
                float t = Time.fixedDeltaTime * 100f; // 조절 가능한 보간 계수
                this.rBody.MovePosition(Vector3.Lerp(this.rBody.position, currentPosition, t));
                this.rBody.MoveRotation(Quaternion.Slerp(this.rBody.rotation, currentRotation, t));
            }
            else
            {
                // Rigidbody에 이동과 회전을 적용합니다.
                this.rBody.MovePosition(this.rBody.position + positionDelta);
                this.rBody.MoveRotation(this.rBody.rotation * rotationDelta);
            }

            // 현재 위치 및 회전을 이전 값으로 업데이트합니다.
            previousPosition = currentPosition;
            previousRotation = currentRotation;
        }
    }
}
반응형

'VR > Oculus Integration' 카테고리의 다른 글

Oculus Integration SDK Hand & Materials  (0) 2024.01.03
활시위 당기는 법  (0) 2023.12.22
OneGrabPhysicsJointTransformer  (0) 2023.12.20
Grabbable (Two Grab Transformers)  (0) 2023.12.19
Grabbable  (0) 2023.12.18
: