Exemplo n.º 1
0
    public void goTo(Vector3 _dest)    //Start moving to position following pest path
    {
        bool isSamePos = Vector3Util.IsAlmostEquals(destination, _dest);

        UpdateafterMovePosition();

        destinationActive = true;
        destination       = _dest;
        updatePath();

        if (!isSamePos)
        {
            m_event.Invoke(
                GetComponent <CorvoPathFinder>().havePath()
                    ?
                EventType.MOVE_START
                    :
                EventType.MOVE_FAILED
                );
        }
    }
Exemplo n.º 2
0
    void FixedUpdate()
    {
        if (!Vector3Util.IsAlmostEquals(transform.position, afterMovePosition))
        {
            stop();
            return;
        }

        CorvoPathFinder pf = GetComponent <CorvoPathFinder>();

        if (destinationActive)
        {
            if (pf)
            {
                if (pf.havePath())
                {
                    checkReachedNode();
                }
                if (Time.time > pathRefreshTime)
                {
                    updatePath();
                }

                if (mustMove)
                {
                    if (pf.havePath())
                    {
                        Vector3 _dir = (pf.getDestination() - transform.position).normalized;
                        if (updateRotation != rotationType.dontRotate)
                        {
                            Vector3 _dir2D;
                            if (updateRotation == rotationType.rotateAll)                          //rotate all
                            {
                                _dir2D = (pf.getDestination() - transform.position).normalized;
                            }
                            else                            //don't update z axis
                            {
                                _dir2D = ((pf.getDestination() - Vector3.up * pf.getDestination().y) - (transform.position - Vector3.up * transform.position.y)).normalized;
                            }

                            transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(_dir2D), Time.deltaTime * rotationSpeed);
                        }

                        if (Vector3.Distance(transform.position, pf.getDestination()) < Time.deltaTime * moveSpeed)
                        {
                            transform.position = pf.getDestination();
                        }
                        else
                        {
                            transform.position = Vector3.MoveTowards(transform.position, pf.getDestination(), Time.deltaTime * moveSpeed);
                        }

                        UpdateafterMovePosition();
                    }
                }
            }
            else
            {
                Debug.LogError("No PathFinder Assigned! please assign component CorvopathFinder to this object.", gameObject);
            }
        }
    }