Ejemplo n.º 1
0
    void Update()
    {
        _lines.SetPosition(0, transform.position);
        _lines.SetPosition(1, (transform.position + (transform.forward * 4f)));

        if (_game.GetState() != GameManager.GameState.Running)
        {
            return;
        }

        float speed    = WalkSpeed * Time.deltaTime;
        float rotSpeed = TurnSpeed * Time.deltaTime;
        float x        = Input.GetAxis("Horizontal") * rotSpeed;
        float z        = Input.GetAxis("Vertical") * speed;

        transform.Translate(0f, 0f, z);
        transform.Rotate(0f, x, 0f);

        if (_ballMachine.IsBallInPossession() && Input.GetButtonDown("Jump"))
        {
            Vector3 normalizedDirection = (_ball.transform.position - transform.position).normalized;
            _brb.AddForce(normalizedDirection * 250f);
        }
    }
Ejemplo n.º 2
0
    public void Transition()
    {
        float goalDistance = Vector3.Distance(transform.position, keeperPosition);
        float distance     = Vector3.Distance(transform.position, _ball.transform.position);

        if (state == State.Idle)
        {
            //if (distance <= 20f && state != State.Take)
            if (distance <= TrackDistance)
            {
                state = State.Track;
            }
            else if (distance <= TakeDistance)
            {
                state = State.Take;
            }
        }
        else if (state == State.Track)
        {
            if (distance > TrackDistance)
            {
                state = State.Idle;
            }
            else if (distance <= TakeDistance && !_ballState.IsBallInPossession())
            {
                state = State.Take;
            }
        }
        else if (state == State.Take)
        {
            if (Vector3.Distance(keeperPosition, transform.position) > RetreatDistance)
            {
                state = State.Retreat;
            }
            else
            {
                if (distance < ReturnDistance)
                {
                    state = State.Return;
                }
                else if (_ballState.IsBallInPossession())
                {
                    state = State.Idle;
                }
            }
        }
        else if (state == State.Return)
        {
            if (goalDistance <= KickDistance)
            {
                state = State.Kick;
            }
        }
        else if (state == State.Kick)
        {
            if (distance >= TakeDistance)
            {
                state = State.Idle;
            }
        }
        else if (state == State.Retreat)
        {
            if (goalDistance <= KickDistance)
            {
                state = State.Idle;
            }
        }
    }