예제 #1
0
    void FixedUpdate()
    {
        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 * speed * 60);
                        }
                        transform.position = Vector3.MoveTowards(transform.position, pf.getDestination(), Time.deltaTime * speed);
                    }
                }
            }
            else
            {
                Debug.LogError("No PathFinder Assigned! please assign component CorvopathFinder to this object.", gameObject);
            }
        }
    }
예제 #2
0
        public void OnUpdate()
        {
            if (_firstUpdate)
            {
                StartIdle();
                _firstUpdate = false;
            }

            if (_isWalkTargetSet)
            {
                //                      if (corvoPathFinder != null && !corvoPathFinder.havePath() && !corvoPathFinder.isCalculating())
                //                    SetWalkVector(_walkTarget, pathFinder.speed);
                _distanceCalcTimer -= Time.deltaTime;
                if (_distanceCalcTimer <= 0)
                {
                    _distanceCalcTimer = 0.1f;
                    float distance = Vector3.Distance(_walkTarget, _wholeNPC.transform.position);
                    if (distance < 1f || (_wholeNPC.TheBrain.CurrentState == NPCState.Patrol && corvoPathFinder != null && !corvoPathFinder.havePath() && !corvoPathFinder.isCalculating()))
                    {
                        if (_wholeNPC.TheBrain.CurrentState == NPCState.Patrol)
                        {
                            _wholeNPC.TheBrain.StartIdle();
                        }
                        StopWalking();
                    }
                    _lastDistance = distance;
                }
            }
            if (_lookDirection != Quaternion.identity)
            {
                _wholeNPC.transform.rotation = _lookDirection;
            }
        }