애니메이션 다운로드
- https://www.mixamo.com
- Unity, No character 로 다운받아서 유니티에 드래그앤 드롭
- Rig -> Humanoid 로 바꾸기
- Animation -> 이름 바꾸기 가능
- Loop Time 체크 (필요하다면)
- Root Transform Rotation -> Based Upon -> Original 로 바꿔서 방향 맞는지 확인
- Animation Clip -> Unity Model 로 애니메이션 확인 가능
Animator 옵션
- Apply Root Motion : 애니메이션안에 이동하는 (좌표는 그대로지만, 모델링이 앞으로 나가는) 경우 제거
- 애니메이션 ReadOnly 는 복붙해서 수정할 수 있음
- 총 위치는 레코드 해서 애니메이션마다 바꿔주자
Animator Condition
- IsWalking 컨디션 추가
- SetBool("IsWalking", true);
캐릭터 회전 가장 쉬운 방법
- transform.forward = Vector3.Lerp(transform.forward, moveDirection, Time.deltaTime * rotateSpeed);
public class Unit : MonoBehaviour
{
[SerializeField] private Animator unitAnimator;
private Vector3 targetPosition;
private float moveSpeed = 4f;
private float rotateSpeed = 10f;
private float stoppingDistance = 0.1f;
private void Update()
{
if(Vector3.Distance(targetPosition, transform.position) > stoppingDistance)
{
Vector3 moveDirection = (targetPosition - transform.position).normalized;
transform.position += moveDirection * moveSpeed * Time.deltaTime;
transform.forward = Vector3.Lerp(transform.forward, moveDirection, Time.deltaTime * rotateSpeed);
unitAnimator.SetBool("IsWalking", true);
}
else
{
unitAnimator.SetBool("IsWalking", false);
}
if(Input.GetMouseButtonDown(0))
{
Move(MouseWorld.GetPosition());
}
}
private void Move(Vector3 targetPosition)
{
this.targetPosition = targetPosition;
}
}
'유니티 게임 개발' 카테고리의 다른 글
텍스트 ContentSize 스크립트 (0) | 2023.03.22 |
---|---|
다중 유닛 중 개별 유닛 선택 (마우스 클릭) (0) | 2023.03.19 |
마우스, Unit Movement / Selection (0) | 2023.03.19 |
Unity Project Setup 고려 사항 (0) | 2023.03.19 |