public override void Update(Cornerback_Controller_FSM cornerback) { if (cornerback.zone.receiverInZone == null) { cornerback.TransitionToState(cornerback.goToZone_State); } 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); } } }
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 Update(Cornerback_Controller_FSM cornerback) { if (cornerback.zone.receiverInZone != null) { cornerback.PlayerToCover = cornerback.zone.receiverInZone.transform; cornerback.TransitionToState(cornerback.cover_inZone_State); } Vector3 zonePos = cornerback.zone.centerPoint; //if didnt reach center of zone then move towards it if ((zonePos - cornerback.transform.position).magnitude > 0.5f) { Vector2 localRight = cornerback.transform.rotation * Vector2.right; cornerback.myRb.AddForce(localRight * cornerback.speed * Time.deltaTime); float angle = Vector2.SignedAngle(zonePos - cornerback.transform.position, new Vector2(1.0f, 0.0f)); cornerback.myRb.MoveRotation(Mathf.LerpAngle(cornerback.myRb.rotation, -angle, cornerback.rotationSpeed * Time.deltaTime)); } else { //look to the opposing side and wait float angle = Vector2.SignedAngle(Vector2.left, new Vector2(1.0f, 0.0f)); cornerback.myRb.MoveRotation(Mathf.LerpAngle(cornerback.myRb.rotation, -angle, cornerback.rotationSpeed * Time.deltaTime)); } }