Exemplo n.º 1
0
    // Update is called once per frame
    public bool Move()
    {
        if (!_isReady)
        {
            return(false);
        }
        if (_idx >= _waypoints.Count)
        {
            _anim.SetFloat("vPreviousSpeed", -1f);
            _anim.SetFloat("hPreviousSpeed", 0);
            _anim.SetBool("IsWalking", false);
            return(false);
        }
        Vector3 myPos     = _src.transform.position;
        Vector3 targetPos = _waypoints[_idx];

        _src.transform.position = Vector3.MoveTowards(myPos, targetPos, _speed * Time.deltaTime);


        // inform the animation what type of movement is happending.
        float dec = PathWalker.AngleDegrees(_src.transform.position, targetPos);


        if (dec >= 0f && dec < 35f)
        {
            SetAnimation(0, 1);
        }
        else if (dec >= 35f && dec < 55f)         // north
        {
            SetAnimation(1, 1);
        }
        else if (dec >= 55f && dec < 125f)          // north west
        {
            SetAnimation(1, 0);
        }
        else if (dec >= 125f && dec < 145f)          // south west
        {
            SetAnimation(1, -1);
        }
        else if (dec >= 145f && dec < 215f)
        {
            SetAnimation(0, -1);
        }
        else if (dec >= 215f && dec < 235f)
        {
            SetAnimation(-1, -1);
        }
        else if (dec >= 235 && dec < 305f)
        {
            SetAnimation(-1, 0);
        }
        else if (dec >= 305f && dec < 325f)
        {
            SetAnimation(-1, 1);
        }
        else if (dec >= 325f)
        {
            SetAnimation(0, 1);
        }


        CheckForNewWaypoint();

        return(true);
    }