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; //baselines BallBug Test Rigidbody ballRb = ballGo.GetComponent <Rigidbody>(); ballRb.isKinematic = true; cornerback.TransitionToState(cornerback.ballCaught_State); } else { 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) if (GameManager.Instance.ballLaunched == true) { cornerback.TransitionToState(cornerback.intercept_State); } } }