public static void WhatDoIDoWithTheBall(Fielder player) { if (GetFurthestRunner() == null) { player.ThrowBall(GetPlayerToThrowBallTo()); return; } Transform baseLocation = GetFurthestRunner().targetBase[0].transform; GetClosestFielderToTransform(baseLocation, false).movementTarget = baseLocation.position; if (player == GetClosestFielderToTransform(baseLocation)) { if (Utility.CheckEqual(player.transform.position, baseLocation.position, 0.1f) && !GameControl.ballInPlay) { player.ThrowBall(GetPlayerToThrowBallTo()); } return; } else { player.ThrowBall(GetPlayerToThrowBallTo()); } }
public void ThrowPitch() { if (fielder.ballInHands == true) { GameControl.curInning.pitchesThrownThisInning += 1; Field.ballHasBeenThrown = false; fielder.anim.SetBool("isThrowing", true); fielder.ballInHands = false; ball.TemporarilyDisableCollision(0.2f); ball.curHeight = 1f; ball.curSpeed = pitchSpeed; ball.maxHeight = 3.0f; ball.startPoint = ball.transform.position; ball.shownHomeRunPopup = false; fielder.team.pitches += 1; Fielder catcher = Field.fielders.Find(x => x.position == Fielder.Position.catcher); ball.endPoint = catcher.glove.position; ball.targetFielder = catcher; } else { fielder.ThrowBall(fielder); } }
public static void FielderAI() { if (runners.Find(x => x.isAdvancing) == null && ballHasBeenThrown) { GameControl.ballInPlay = false; } Fielder fielderWithBall = fielders.Find(x => x.ballInHands); bool pitcherHasBall = false; if (fielderWithBall != null) { ball.transform.parent = fielderWithBall.glove.gameObject.transform; ball.transform.localPosition = Vector3.zero; ball.curHeight = 1f; pitcherHasBall = fielderWithBall.position == Fielder.Position.pitcher; } else { if (ball != null) { ball.transform.parent = fieldParent; } } if (fieldersCanReact) { if (GameControl.ballInPlay || pitcherHasBall == false) { MoveFieldersToPlayPosition(); if (ball.hasHitGround && ballHasBeenThrown == false) { GetClosestFielderToTransform(ball.transform, false).movementTarget = ball.transform.position + ballOffset; } else { GetClosestFielderToLocation(ballLandingSpot).movementTarget = ballLandingSpot; } if (fielderWithBall != null) { WhatDoIDoWithTheBall(fielderWithBall); } } } if (GameControl.ballInPlay == false) { if (fielderWithBall != null && fielderWithBall.position != Fielder.Position.pitcher) { fielderWithBall.ThrowBall(GetPlayerToThrowBallTo()); } else if (fielderWithBall != null && fielderWithBall.position == Fielder.Position.pitcher) { GameControl.instance.SetCameraToFollowBall(false); GameControl.playIsActive = false; fieldersCanReact = false; ball.wasHit = false; } MoveFieldersToStartPosition(false); } if (ball != null && ball.targetFielder != null) { ball.targetFielder.movementTarget = ball.endPoint; } }