본문 바로가기
Project/[Unity] 지진 시뮬레이션

[Unity] 지진 시뮬레이션 - 4 (플레이어 움직임)

by ruki 2024. 3. 21.

본격적으로 게임 시스템을 만들기 전에 플레이어를 만들 것이다.


먼저 간단한 오브젝트를 생성한다.

 

여기에 Rigidbody를 추가하고 조건을 설정한다.

 

플레이어는 회전하면 안 되기 때문에 회전을 비활성해야 한다.

 

오브젝트에 CharacterController를 추가한다.

CharacterController : Unity에서 제공하는 컨트롤러로 오브젝트의 움직임을 더욱 자연스럽고 편리하게 만들 수 있다.

 

플레이어 이동 코드를 추가한다.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class playerMove : MonoBehaviour
{
    public float playerSpeed;
    public CharacterController characterController;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");

        characterController.Move(new Vector3(h, 0, v) * playerSpeed * Time.deltaTime);
    }
}

 

이동이 잘 된다.