public override void UpdateInsistence() { Insistence = 0; // If dodged recently, don't dodge so soon. if (Time.time - timeSinceLastJet < WaitPeriod) { return; } Tank selfTank = controller.SelfTank; bool shouldDodge = false; // First calculate all bullet trajectories and check if they'll hit us in 0.5 seconds foreach (Bullet bullet in BulletInstanceHandler.Instance.BulletInstances) { Vector2 targetPos = selfTank.transform.position; Vector2 curFireVec = bullet.Body.velocity.normalized; Vector2 curFirePos = bullet.Body.position; Ray ray = new Ray(curFirePos, curFireVec); float shortestDist = Vector3.Cross(ray.direction, (Vector3)(targetPos) - ray.origin).magnitude; bool canHitIfFired = shortestDist < selfTank.Hull.Schematic.Size.x / 2f; Vector2 targetVec = targetPos - curFirePos; float distTravelledByBullet = (bullet.Body.velocity * 0.5f).magnitude; bool fireVecFacingTarget = Vector2.Angle(curFireVec, targetVec) < 90f; bool inRange = targetVec.magnitude < distTravelledByBullet; if (inRange && canHitIfFired && fireVecFacingTarget) { shouldDodge = true; break; } } if (!shouldDodge) { Tank oppTank = controller.TargetTank; shouldDodge = AIUtility.IsInOpponentFireVec(selfTank.StateInfo, oppTank.StateInfo, oppTank.Hull.GetAllWeapons()); } if (shouldDodge) { Insistence = 75; } }