본격적으로 게임 시스템을 만들기 전에 플레이어를 만들 것이다.
먼저 간단한 오브젝트를 생성한다.
여기에 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);
}
}
이동이 잘 된다.
'Project > [Unity] 지진 시뮬레이션' 카테고리의 다른 글
[Unity] 지진 시뮬레이션 - 6 (장애물 데미지 구현) (2) | 2024.03.26 |
---|---|
[Unity] 지진 시뮬레이션 - 5 (추가 플레이어 이동, 디자인) (0) | 2024.03.22 |
[Unity] 지진 시뮬레이션 3 (조명과 장애물 추가) (0) | 2024.03.20 |
[Unity] 지진 시뮬레이션 - 2 (지진 구현) (1) | 2024.03.19 |
[Unity] 지진 대피 시뮬레이션 -1 (3D 타일맵을 이용하여 건물 제작) (0) | 2024.03.17 |