public override void OnTriggerEnter(Cornerback_Controller_FSM cornerback, Collider2D other)
    {
        if (other.gameObject.tag == "Ball")
        {
            Transform ballGo = other.gameObject.transform.parent;

            //check the height of the ball
            //Debug.Log("Ball height: " + "<color=green><b> " + ballGo.transform.position.z + "</b></color>");
            bool canCatchBall = ballGo.transform.position.z <= GameManager.Instance.catchableHeight;

            //try to catch ball
            if (canCatchBall)
            {
                other.gameObject.tag = "BallCaught";

                ballGo.parent             = cornerback.transform;
                ballGo.transform.position = cornerback.transform.position;

                cornerback.TransitionToState(cornerback.ballCaught_State);
            }
            else
            {
                cornerback.TransitionToState(cornerback.cover_State);
            }
        }
    }
 public override void OnTriggerExit(Cornerback_Controller_FSM cornerback, Collider2D other)
 {
     if (other.gameObject.tag == "Receiver")
     {
         Debug.Log("Trigger in Push State");
         cornerback.TransitionToState(cornerback.cover_State);
     }
 }
Example #3
0
 public override void OnTriggerExit(Cornerback_Controller_FSM cornerback, Collider2D other)
 {
     /*
      * something is wrong with the OnTriggerExit. The Reset somehow forces OnTriggerExit to fire
      * for now the hack is to wait a second until after the reset before we react to the event
      * however this is not a stable sollution
      */
     if (other.gameObject.tag == "Receiver" && trigger == true)
     {
         Debug.Log("Trigger in Push State");
         cornerback.TransitionToState(cornerback.cover_State);
     }
 }
    public override void Update(Cornerback_Controller_FSM cornerback)
    {
        Vector2 localRight = cornerback.transform.rotation * Vector2.right;

        cornerback.myRb.AddForce(localRight * cornerback.speed * Time.deltaTime);

        //mechanism to simulate reaction time for cornerback
        if (doReact == true)
        {
            cornerback.StartCoroutine(ApplyRotation(cornerback));
            doReact = false;
        }

        //try to intercept the ball if its in the air
        if (cornerback.qB_Controller.Receiver_current == cornerback.PlayerToCover.gameObject)
        {
            //here we make sure that onlt the right cornerback tries to intercept the ball
            if (cornerback.ball_controller.launched == true)
            {
                cornerback.TransitionToState(cornerback.intercept_State);
            }
        }
    }