velog 

https://velog.io/@-_-/개발일지-1


서바이블 게임 

마우스 클릭에 따라 해당 위치로 이동하는 캐릭터로  기본적인 부분 테스트 


viewimage.php?id=2abcdd23dad63db0&no=24b0d769e1d32ca73cec87fa11d0283141b58444220b0c04398dc02aecde06e50774db5eab2fa798857eb7475ab7945de8d942dfde44a7528c98fd3c2474

unity 어셋 스토어에서 Riko 다운 

image.png

구매하거나 illegal 사이트에서 테스트용으로 다운 

길찾기는 게임의  맵을 저장할 데이터타입을 잘 생각해보고 결정해야 되니까 먼저 unity navigation 사용 

https://docs.unity3d.com/kr/530/Manual/nav-Overview.html

navigation bake 하고 

image.png

리코에 Move 스크립트랑 NavMeshAgent 스크립트 달아주면 완성

image.png

animation은 새로 작성해서 rotateAngle,velocity 추가

idle -> run 진입은 velocity > 0.1 

run->idle 돌아오는건 velocity < 0.6

HasExitTime 은 체크해제 

image.png

또한 Run 상태는 우클릭 -> create new blend tree in state 해서 하위상태를 세팅해줌

image.png

왼쪽,오른쪽으로 달리는 애니는 riko 캐릭패키지에 있는 runL runR 등 사용 

RunL이랑 RunR을 0.4/-0.4로 설정한 이유는 

NavMeshAgent의 초당회전속도가 기본값인 120/s 이고 

fps가 200프레임 나올때 전프레임의 Rotation방향이랑 this프레임의 각차이가 0.4이기 때문 (최대로 회전중일때) 

사실 deltatime을 추가 계산해줘야 정확함,추후 추가


velocity에 따라 달리는 애니메이션의 속도를 조절하면 자연스러움, 빠른 속도로 이동하면 3.4f정도가 적당(NavMeshAgent 기본속도일때)



Move.cs 소스:


using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.AI;


public class Move : MonoBehaviour

{

    NavMeshAgent agent;

    Rigidbody rigid;

    float rotatedAng;

    float preAngles ;

    Animator animator;

    float velocity;


    public float RotatedAng { 

        get => rotatedAng;

        set

        {

            rotatedAng = value;

            if (value > 0.4f)

            {

                rotatedAng = 0.4f;

            }

            else if(value < -0.4f)

            {

                rotatedAng = -0.4f;

            }

        }

    }

    public float Velocity { 

        get => velocity;

        set

        {

            velocity = value;

            if (value > 3.4f)

            {

                velocity = 3.4f;

            }

        }

    }

    // Start is called before the first frame update

    void Start()

    {

        agent = GetComponent<NavMeshAgent>();

        rigid = GetComponent<Rigidbody>();

        animator = GetComponent<Animator>();

    }

    // Update is called once per frame

    void Update()

    {

        if (Input.GetMouseButtonDown(0))

        {

            RaycastHit hit;


            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100))

            {

                agent.destination = hit.point;

            }

        }

        if (Time.frameCount > 0)

        {

            //print(120 * Time.deltaTime);s

            RotatedAng = preAngles - transform.rotation.eulerAngles.y;

            animator.SetFloat("rotateAngle", RotatedAng);

            Velocity = agent.velocity.magnitude;

            animator.SetFloat("velocity", velocity);

        }

        preAngles = transform.rotation.eulerAngles.y;

    }

}


개발일지1-끝

2에서는 맵을 세팅하고 맵세팅에 따른 findPath 변경등