캐릭터 움직임의 기초를 제공하는 Character Controller 컴포넌트를 추가하여 장애물을 고려한 이동 처리를 구현해보자.
경사진 지역과 계단 지역을 만들어준다.

플레이어 오브젝트에 Character Controller 컴포넌트를 부착한다.

Character Controller 컴포넌트를 이용하여 이동하도록 코드를 수정한다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
//...중략
private CharacterController characterController;
private void Start()
{
characterController = GetComponent<CharacterController>();
}
void Update()
{
//...중략
Vector3 movementDirection = new Vector3(horizontalInput, 0, verticalInput);
float magnitude = Mathf.Clamp01(movementDirection.magnitude) * speed;
movementDirection.Normalize();
characterController.SimpleMove(movementDirection * magnitude);
//...중략
}
}
CharacterController.SimpleMove
public bool SimpleMove (Vector3 speed);
중력을 적용 받음
Grounded 체크 가능
y축의 속도는 무시됨
Time.deltaTime은 내장되어 있음