RigidbodyConstraints : 회전과 위치 제어

2024. 3. 9. 10:17·Unity
반응형
유니티 RigidbodyConstraints는 리지드바디의 회전과 위치를 제어하는 데 사용되는 enum입니다. 각 옵션은 다음과 같은 의미를 가집니다.

 

회전 제어:

  • FreezeRotationX: X축 회전을 동결합니다. (X축 회전 불가능)
  • FreezeRotationY: Y축 회전을 동결합니다. (Y축 회전 불가능)
  • FreezeRotationZ: Z축 회전을 동결합니다. (Z축 회전 불가능)

위치 제어:

  • FreezePositionX: X축 이동을 동결합니다. (X축 이동 불가능)
  • FreezePositionY: Y축 이동을 동결합니다. (Y축 이동 불가능)
  • FreezePositionZ: Z축 이동을 동결합니다. (Z축 이동 불가능)

예시

단일 제어 

Rigidbody rigid = GetComponent<Rigidbody>();

// X축 회전 동결
rigid.constraints = RigidbodyConstraints.FreezeRotationX;

 

 

| 연산자를 사용해 여러개 제어

// X, Y축 회전 동결
rigid.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY;

// X, Y, Z축 회전 동결
rigid.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;

// X축 회전, Y, Z축 이동 동결
rigid.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezePositionZ;

 

기존 제약 유지

// X축 회전 추가
rigidbody.constraints |= RigidbodyConstraints.FreezeRotationX;

// Y축 회전 제거
rigidbody.constraints &= ~RigidbodyConstraints.FreezeRotationY;

 

비트 마스크 활용

// X, Y축 회전 동결
int mask = (int)RigidbodyConstraints.FreezeRotationX | (int)RigidbodyConstraints.FreezeRotationY;
rigid.constraints = (RigidbodyConstraints)mask;

 

활용 방법

  • 캐릭터 회전 제한: 캐릭터가 특정 방향으로만 회전하도록 제어
  • 오브젝트 고정: 오브젝트가 특정 위치에서 움직이지 않도록 제어
  • 게임 플레이 제작: 움직임 제한을 이용한 퍼즐, 탈출 게임 등 제작

추가 정보

  • RigidbodyConstraints는 비트 마스크(bitmask) 형식으로 사용됩니다.
  • 여러 옵션을 함께 사용하려면 | 또는 & 연산자를 사용합니다.
  • None 옵션을 사용하면 모든 제어를 해제합니다.
  • 유니티 공식 문서: https://docs.unity3d.com/2021.1/Documentation/ScriptReference/RigidbodyConstraints.html
저작자표시 비영리 변경금지 (새창열림)

'Unity' 카테고리의 다른 글

Unity Shader : 코드 분석  (0) 2024.03.14
Unity Shader : 기초  (0) 2024.03.13
Rigidbody에서 오브젝트에 힘을 가할 때 사용되는 ForceMode  (0) 2024.02.21
Unity에서 UnityWebRequest를 이용해 웹 접속하는 방법  (0) 2024.02.16
LayerMask 활용하기  (0) 2024.02.13
'Unity' 카테고리의 다른 글
  • Unity Shader : 코드 분석
  • Unity Shader : 기초
  • Rigidbody에서 오브젝트에 힘을 가할 때 사용되는 ForceMode
  • Unity에서 UnityWebRequest를 이용해 웹 접속하는 방법
코샵
코샵
나의 코딩 일기장
    반응형
  • 코샵
    끄적끄적 코딩 공방
    코샵
    • 분류 전체보기 (727)
      • 스마트팜 (1)
      • 상품 추천 (223)
      • DataBase (0)
        • MongoDB (4)
        • PostgreSQL (0)
      • 하드웨어 (18)
      • 일기장 (4)
      • 파이썬 (130)
        • Basic (41)
        • OpenCV (8)
        • Pandas (15)
        • PyQT (3)
        • SBC(Single Board Computer) (1)
        • 크롤링 (14)
        • Fast API (29)
        • Package (6)
      • Unity (138)
        • Tip (41)
        • Project (1)
        • Design Pattern (8)
        • Firebase (6)
        • Asset (2)
      • Linux (4)
      • C# (97)
        • Algorithm (11)
        • Window (7)
      • TypeScript (51)
        • CSS (10)
      • Git (11)
      • SQL (5)
      • Flutter (10)
        • Tip (1)
      • System (1)
      • BaekJoon (6)
      • Portfolio (2)
      • MacOS (1)
      • 유틸리티 (1)
      • 서비스 (6)
      • 자동화 (3)
      • Hobby (10)
        • 물생활 (10)
        • 식집사 (0)
  • 인기 글

  • 태그

    리뷰이관
    list
    C#
    programming101
    devlife
    파이썬
    rtsp
    믈레코비타멸균우유
    codingcommunity
    셀레니움
    unity
    카페24리뷰이관
    programmerlife
    긴유통기한우유
    스크립트 실행
    유니티
    codingtips
    learntocode
    스크립트 실행 순서
    리스트
    쇼핑몰리뷰
    라떼우유
    appdevelopment
    카페24리뷰
    cv2
    Python
    상품 리뷰 크롤링
    ipcamera
    스마트스토어리뷰
    리뷰관리
  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
코샵
RigidbodyConstraints : 회전과 위치 제어
상단으로

티스토리툴바