private void UpdateDirection()
    {
        if (velocity == Vector2.zero)
        {
            return;
        }

        float angle = Mathf.Atan2(velocity.y, velocity.x) * Mathf.Rad2Deg;

        if (angle > -67.5f && angle <= -22.5f)
        {
            direction = Tree.Direction.FrontRight;
        }
        else if (angle > -22.5f && angle <= 22.5f)
        {
            direction = Tree.Direction.Right;
        }
        else if (angle > 22.5f && angle <= 67.5f)
        {
            direction = Tree.Direction.BackRight;
        }
        else if (angle > 67.5f && angle <= 112.5f)
        {
            direction = Tree.Direction.Back;
        }
        else if (angle > 112.5f && angle <= 157.5f)
        {
            direction = Tree.Direction.BackLeft;
        }
        else if (angle > 157.5f || angle <= -157.5f)
        {
            direction = Tree.Direction.Left;
        }
        else if (angle > -157.5f && angle <= -112.5f)
        {
            direction = Tree.Direction.FrontLeft;
        }
        else
        {
            direction = Tree.Direction.Front;
        }
    }
示例#2
0
    private void UpdateDirection()
    {
        if (velocity == Vector2.zero) return;
        
        float angle = Mathf.Atan2(velocity.y, velocity.x) * Mathf.Rad2Deg;

        if      (angle >  -67.5f && angle <=  -22.5f) direction = Tree.Direction.FrontRight;
        else if (angle >  -22.5f && angle <=   22.5f) direction = Tree.Direction.Right;
        else if (angle >   22.5f && angle <=   67.5f) direction = Tree.Direction.BackRight;
        else if (angle >   67.5f && angle <=  112.5f) direction = Tree.Direction.Back;
        else if (angle >  112.5f && angle <=  157.5f) direction = Tree.Direction.BackLeft;
        else if (angle >  157.5f || angle <= -157.5f) direction = Tree.Direction.Left;
        else if (angle > -157.5f && angle <= -112.5f) direction = Tree.Direction.FrontLeft;
        else direction = Tree.Direction.Front;
    }