본문 바로가기
Unity Portfolio/ZombieShooter

1. 프로젝트 세팅, 플레이어 이동 Movement Settings

by 첨부엉. 2024. 7. 6.
반응형

빌트인 3D 프로젝트로 생성하고

이름은 ZombieShooter로 생성

 

1. 사용할 패키지 준비

 

  • Universal RP
  • Cinemachine
  • Input System

 

2.에셋 준비

POLYGON Apocalypse - Low Poly 3D Art by Synty | 3D Urban | Unity Asset Store

 

POLYGON Apocalypse - Low Poly 3D Art by Synty | 3D 도시 | Unity Asset Store

Elevate your workflow with the POLYGON Apocalypse - Low Poly 3D Art by Synty asset from Synty Studios. Find this & other 도시 options on the Unity Asset Store.

assetstore.unity.com

 

 

RIFLE Basic - Mocap Animation Pack | 3D Animations | Unity Asset Store

 

RIFLE Basic - Mocap Animation Pack | 3D 애니메이션 | Unity Asset Store

Elevate your workflow with the RIFLE Basic - Mocap Animation Pack asset from MoCap Online. Find this & other 애니메이션 options on the Unity Asset Store.

assetstore.unity.com

 

3. 다운받은 패키지와 프로젝트 세팅하기

1. URP 패키지 준비

URP로 사용할 예정이니 보통 에셋에는 URP Textures 패키지를 따로 포함하고 있음 임포트하여 받아주기

Project 뷰에서 Asset 폴더 위에 오른쪽 마우스 클릭하고 새로운 URP 렌더링 파일 생성하기

Project Settings의 Scriptable Render Pipeline Settings에 방금 만든 URP 렌더링 파일 연결하기

 

폴더명을 이렇게 준비하고 사용할 캐릭터를 꺼내서 준비하기

2. Input System 패키지 준비하기, 플레이어 이동 세팅

플레이어에게 Player Input 컴포넌트를 달아주고

Create 버튼을 클릭해 새로 생성하는데 이때 Player 이외의 UI Maps는 삭제하고 Player 맵에 Move 와 Fire 만 놔두고 삭제한다.

Sprint Action을 추가하여 Shift 키를 누르면 달릴 수 있게 한다.

 

PlayerCtrl.cs 스크립트를 생성하여 플레이어에게 연결한 다음 아래와 같이 작성한다.

더보기
#pragma warning disable IDE0051

using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerCtrl : MonoBehaviour
{

    private Animator anim;
    private new Transform transform;
    private Vector3 moveDir;
    private float tmpSprint;
    private float isSprint; // 1 : true , 0 : false

    private void Start()
    {
        anim = GetComponent<Animator>();
        transform = GetComponent<Transform>();
    }

    private void Update()
    {
        // 자연스러운 sprint 사용을 위한 보간
        tmpSprint = Mathf.Lerp(tmpSprint, isSprint, Time.deltaTime * 10);
        anim.SetFloat("Sprint", tmpSprint);
    }

    #region UNITY_EVENTS
    public void OnMove(InputAction.CallbackContext ctx)
    {
        Vector2 dir = ctx.ReadValue<Vector2>();
        
        // 2차원 좌표를 3차원 좌표로 변환
        moveDir = new Vector3(dir.x, 0, dir.y);

        anim.SetFloat("Horizontal", moveDir.x);
        anim.SetFloat("Vertical", moveDir.z);

    }
    public void OnFire(InputAction.CallbackContext ctx)
    {
        if (ctx.performed)
        {
            anim.SetTrigger("Attack");
        }
    }

    public void OnSprint(InputAction.CallbackContext ctx)
    {
        if(ctx.performed)
            isSprint = 1;
        else
            isSprint = 0;
    }
    #endregion
}

 

설정은 Invoke Unity Events 로 설정하고 OnMove, OnFire, OnSprint 를 연결한다.

 

3.애니메이션 준비하기

우리는 파라미터를 Sprint, Horizontal, Vertical 세가지를 쓸 예정이고 아래와 같이 만들 예정

1. MoveBlendTree

Blend Type 은 1D로 설정하고 Sprint 파라미터로 변경하며

두개의 Blend Tree를 생성하고 이름은 위와 같이 바꿔준다.

 

2. WalkBlendTree

Blend Type은 2D Simple Directional을 사용하고 

파라미터는 Horizontal 과 Vertical 을 사용한다.

idle 포함 4방향 걷기 애니메이션을 연결한다.

이때 CIR이 붙어 있는 애니메이션 설정은 아래와 같다.

Root Transform Rotation 의 Bake Into Pose 설정이 언체크 되어 있다.

체크한거

 

체크 안한거

3. JogBlendTree

WalkBlendTree와 동일하게 연결하기

 

4. Cinemachine 패키지 연결하기

하이러키 뷰에 Virtual Camera 생성하고 속성은 아래와 같이 설정하기

 

이제 실행해보면 기본적인 움직임은 완료가 되었다.

 

 

반응형