본문 바로가기
Programming/C# * Unity

[Unity] 04. 애니메이션(Animation)

by 고막고막 2019. 3. 7.

Character Controller

  • Slope Limit : 등판 각도
  • Step Offset : 계단 높이
  • Skin Width : 폭 너비(반지름의 10%가 이상적인 설정값)
  • Min Move Distance : 최소 이동 거리
  • Center & Radius : Capsule Collider 컴포넌트와 같은 역할로 Character Controller에 내장되어 있음. 다른 물체와 접촉이 되었는가 안 되었는가를 물리적으로 계산함. 몸체에 맞게 하는 경우(연산이 많이 들어감) 또는 일반적으로는 캡슐 모양으로 준다.
    public float movSpeed = 5f;     //이동     public float rotSpeed = 120f;   //회전     CharacterController controller; //컴포넌트(기능을 모아놓은 부품): 값이 담겨있지 않은 변수임으로 레퍼런스 요구     Vector3 moveDirection;          //이동방향     float jumpSpeed = 10f;          //점프시 속도     float gravity = 20f;            //중력 적용      void Start()     {         controller = GetComponent<CharacterController>(); //해당 기능을 가져오는 리모컨 역할     }      void Update()     {         //Plane에 닿아있다면         if (controller.isGrounded) // is->boolean         {             // 키보드 값 가져오기             float ver = Input.GetAxis("Vertical");    //위,아래 키             float hor = Input.GetAxis("Horizontal");  //좌,우 키              // 회전 기능             float rot = hor * rotSpeed * Time.deltaTime;             transform.Rotate(Vector3.up*rot);              // 이동 기능(CharacterController)             // CharacterController의 좌표는 Local→World로 변환되기로 약속             moveDirection = new Vector3(0, 0, ver * movSpeed);             moveDirection = transform.TransformDirection(moveDirection);              // 점프 기능             if (Input.GetButton("Jump"))                 moveDirection.y = jumpSpeed;         }          // 중력의 적용(떨어질 때)         moveDirection.y -= gravity * Time.deltaTime;          // CharactertController로 이동/점프 수행         controller.Move(moveDirection * Time.deltaTime);

 

 

Animation

  • Legacy : 이미 만들어진 애니메이션을 플레이. 속도↑
  • Mechanim : Final State Machine으로 애니메이션을 편집할 수 있음. 휴머노이드형의 캐릭터를 가져올 수 있다.

    Animation ani;     int selAni = -1;      void Start()     {         ani = GetComponent<Animation>();     }      void Update()     {         float ver = Input.GetAxis("Vertical");         float hor = Input.GetAxis("Horizontal");         float fire = Input.GetAxis("Fire1");         bool isJump = Input.GetButton("Jump");         if (ver != 0)         {             if (selAni != 1)                 ani.Stop();             ani.Play("run");             selAni = 0;         }         else if (hor != 0)         {             ani.Play("walk");             selAni = 1;         }         else if (isJump == true)         {             ani.Play("attack");             selAni = 2;         }         else if (fire != 0)             ani.Play("salute");

 

Animator

에셋에 내장되어 있는 애니메이션 활용하는 방법. 디폴트로 설정하면 항목에 불빛이 들어오며 활성화 된다. spin controller의 speed로 회전속도를 보정할 수 있다.

 

 

 

 

'Programming > C# * Unity' 카테고리의 다른 글

[Unity] 06. 스카이박스(Sky Box)  (0) 2019.03.07
[Unity] 05. 충돌(Colliders)  (0) 2019.03.07
[C#] for문으로 최소공배수 구하기  (0) 2019.03.06
[C#] while문과 do while문 비교  (3) 2019.03.05
[Unity] 03. 지형(Terrain)  (0) 2019.03.04