상세 컨텐츠

본문 제목

유니티 땅(ground) 체크하기

유니티/기능

by MJ_119 2025. 1. 14. 00:21

본문

유니티 땅(ground) 체크하기

 

1. 캐릭터 컨트롤러 컴포넌트를 사용해서 검사 하는 방법.

isGrounded = characterController.isGrounded;

 

2. 피직스.체크스피어로 작은 구를 만들어서 구가 땅에 닿았는지 확인 

- 땅 오브젝트를 ground 레이어로 설정하고 groundMask도 ground로 설정.

- 기즈모를 그려서 구의 크기를 조절해가면서 바닥 체크

[Header("Ground Check")]
public LayerMask groundMask;
public bool isGrounded;


isGrounded = Physics.CheckSphere(transform.position, 0.07f, groundMask);
    void OnDrawGizmos()
    {
        // 체크하는 구체를 시각화
        Gizmos.color = isGrounded ? Color.green : Color.red;
        Gizmos.DrawWireSphere(transform.position, 0.07f);
    }

관련글 더보기