디스크 골프 [#7] - 디스크 골대 힌지 조인트 적용하기
골대의 체인을 만들었는데 골대를 자세히 보니 실제 디스크 골프 골대는 체인 하나를 U자 모양으로 이어서 걸어논 모양인데 나는 체인을 직선과 곡선 사이의 형태로 만들었어서 체인을 U자 모양으로 새로 만들어주었다.
실제 골대는 바스킷과 체인사이에 여유가 있기 때문에 그걸 반영해서 모양을 잡아줬고,
Metal 메테리얼을 넣어 바스켓의 크기를 약간 늘리고 디스크가 들어갈 수 있도록 전체적인 크기를 줄여주었다.
그리고 체인을 복사해서 회전시킨다음 망을 만들어 줬다.
그리고 DiscExample 스크립트를 만들어서 골대로 디스크를 한번 날려보았다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DiscExample : MonoBehaviour
{
private Rigidbody rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
this.rb.AddForce(Vector3.right * -600f);
}
}
그런데 쇠사슬이 디스크보다 질량이 커서 그런지 디스크가 바스켓에 담기지 못하고 그대로 추락해버렸다. 그래서 체인의 리지드바디의 질량을 줄이고 다시 한번 실행해보았다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Chain : MonoBehaviour
{
public string ignoredLayer = "Basket";
[SerializeField]
private Rigidbody[] links;
private void Start()
{
Physics.IgnoreLayerCollision(gameObject.layer, LayerMask.NameToLayer(ignoredLayer), true);
links = GetComponentsInChildren<Rigidbody>();
for (int i =0; i < links.Length; i++)
{
links[i].mass = 0.1f;
Debug.Log(links[i].mass);
}
}
}
그런데 질량을 매우 낮게 설정하자 전과 같이 체인사이의 관절 부분이 터지는 현상이 발생했다.
실제 게임에서 이런 버그가 발생한다면 매우 치명적일 것이기 때문에 방법을 찾아야 했다.
문제를 해결하기 위해서 유니티 공식문서의 도움을 받았다.
https://docs.unity3d.com/Manual/RagdollStability.html
Unity - Manual: Joint and Ragdoll stability
Joint and Ragdoll stability This page provides tips for improving JointA physics component allowing a dynamic connection between Rigidbody components, usually allowing some degree of movement such as a hinge. More infoSee in Glossary and Ragdoll stability.
docs.unity3d.com
조인트의 전처리기능 (Enable Preprocessing)기능을 비활성화하면 관절이 분리되는 걸 방지할 수 있다고 한다. 전처리기능을 비활성화 한다음 다시 실행해보았다.
포스트프로세싱기능을 비활성화하자 체인이 터지는 현상이 사라졌다.