상세 컨텐츠

본문 제목

유니티 피봇, 고정 타게팅 위치 조절하기

유니티/기능

by MJ_119 2024. 10. 14. 23:49

본문

- 피봇이 하단에 있어야 씬 모드에서 오브젝트 배치할때 편함.

- 큐브의 피봇은 오브젝트의 센터에 있어서 씬에 배치할때 아래쪽이 잠기는 현상이 발생.

 

 

목표를 고정 타게팅할때 메쉬렌더러를 체크하고, 있으면

aim.position = target.GetComponent<Renderer>().bounds.center;

코드를 적용해서 메쉬렌더러의 정중앙으로 Aim(목표)을 고정시킴.

 

이 코드 없이 그냥 Aim을 target.position으로 하면, 피봇이 오브젝트의 바닥에 있어서 중앙이 아니라 오브젝트의 바닥을 목표로 공격함.

private void UpdateAimPosition()
    {
        Transform target = Target();

        if( target != null && isLockingToTarget )
        {
            if(target.GetComponent<Renderer>() != null)
            {
                aim.position = target.GetComponent<Renderer>().bounds.center;
            }
            else
            {
                aim.position = target.position;
            }
            return;
        }

        aim.position = GetMouseHitInfo().point;

        if (!isAimingPrecisely)
        {
            aim.position = new Vector3(aim.position.x, transform.position.y + 1, aim.position.z);
        }
        //aim.position = new Vector3(GetMousePosition().x, transform.position.y + 1, GetMousePosition().z);
    }

관련글 더보기