Exemplo n.º 1
0
    public void Init()
    {
        NodeContainer.CreateNodes();

        _curNode = NodeContainer.StartNode;

        PlayerController.Reset();
    }
Exemplo n.º 2
0
    void Init()
    {
        NodeContainer.CreateNodes();

        _curNode = NodeContainer.StartNode;
    }
Exemplo n.º 3
0
    void Update()
    {
        if (Input.GetMouseButtonDown(1)) // mouse right
        {
            Reset();

            // 클릭된 노드를 끝 노드로 지정
            Ray          ray  = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit[] hits = Physics.RaycastAll(ray);
            for (int i = 0; i < hits.Length; i++)
            {
                RaycastHit hit  = hits[i];
                Node       node = hit.collider.GetComponent <Node>();
                if (node != null && !node.IsBlock)
                {
                    NodeContainer.EndNodePositionIndex = node.PositionIndex;
                    break;
                }
            }

            // 캐릭터에서 가장 가까운 노드를 시작 노드로 지정
            Node       startNode = NodeContainer.StartNode;
            Collider[] colliders = Physics.OverlapSphere(Player.transform.position, 1.5f);
            for (int i = 0; i < colliders.Length; i++)
            {
                Collider collider = colliders[i];
                if (collider.gameObject.tag == "Node")
                {
                    Node node = collider.gameObject.GetComponent <Node>();
                    if (node != null)
                    {
                        if (startNode == null)
                        {
                            startNode = node;
                        }
                        else if (
                            node.IsBlock == false &&
                            (Vector3.Distance(Player.transform.position, startNode.transform.position) >
                             Vector3.Distance(Player.transform.position, node.transform.position))
                            )
                        {
                            startNode = node;
                        }
                    }
                }
            }
            NodeContainer.StartNodePositionIndex = startNode.PositionIndex;

            // 맵 재구성
            NodeContainer.CreateNodes();

            // 경로 탐색
            AStar.Init();
            AStar.AutoStartToSearch = true;
        }

        if (_moving)
        {
            // 방향
            Player.transform.LookAt(_targetNode.transform.localPosition + new Vector3(0, this.transform.localPosition.y, 0));
            //Vector3 dir = _targetNode.transform.localPosition - Player.transform.localPosition;
            //Vector3 newDir = Vector3.RotateTowards(Vector3.forward, dir, TurnSpeed, 0.0f);
            //Player.transform.rotation = Quaternion.LookRotation(newDir);

            Player.transform.Translate(Vector3.forward * Speed * Time.deltaTime);

            if (Vector3.Distance(Player.transform.localPosition, _targetNode.transform.localPosition) < 0.3f)
            {
                if (GetNextNode() == false)
                {
                    // 목적지 도착
                    Reset();
                    Player.Animate(ConstVar.AniType.Attack);
                    U.d("Move Complete!!!");
                }
            }
        }
    }
Exemplo n.º 4
0
    private void Start()
    {
        NodeContainer.CreateNodes();

        _curNode = NodeContainer.StartNode;
    }
Exemplo n.º 5
0
    void Start()
    {
        NodeContainer.CreateNodes();

        Reset();
    }