public void ShootNow(GameObject target, Vector3 targetPos, Vector3 targetDir, float targetSpeed) { if (targetSpeed > maxSpeedNoticed) { maxSpeedNoticed = targetSpeed; } Vector3 aimedPos = targetPos; Vector3 shootDir = aimedPos - transform.position; if (targetPos != targetPos && (targetPos - targetPos).magnitude > 0.004f && Vector3.Angle(transform.forward, targetDir) % 180 > 5) { shootDir += Vector3.Distance(aimedPos, transform.position) * targetDir * targetSpeed / 22; } Ray ray = new Ray(transform.position, shootDir); int layerMask = 1 << 0; RaycastHit hit; if (!Physics.SphereCast(ray, 0.75f, out hit, Vector3.Distance(transform.position, aimedPos), layerMask, QueryTriggerInteraction.Ignore) || (shootDir == aimedPos - transform.position && Vector3.Distance(transform.position, targetPos) <= 15)) { if (Vector3.Angle(transform.forward, shootDir) <= 70 && targetSpeed >= maxSpeedNoticed) { bot.ShootInDirection(shootDir); GizmosService.Line(transform.position, aimedPos, 3); Debug.Log("Shot called by ally"); } } }
IEnumerator Shoot(GameObject target) { Vector3 targetPos = target.transform.position; /*if (Vector3.Distance (targetPos, transform.position) <= 10) { * * Vector3 shootDir = targetPos - transform.position; * GizmosService.Line (transform.position, targetPos, 2); * * * /*Ray ray = new Ray (transform.position, shootDir); * * int layerMask = ~LayerMask.GetMask(new string[]{ "TeamRed", "TeamBlue", "Rocket", "Flag" }); * /*if (team.team_ID == 0) * layerMask = ~(1 << 9); * else * layerMask = ~(1 << 8);*//* * * if (!Physics.SphereCast(ray, 0.7f, Vector3.Distance(transform.position, targetPos), layerMask)) {*//* * * * if (Vector3.Angle(transform.forward, shootDir) <= 70) * bot.ShootInDirection (shootDir); * * * //} * * * }*/ float timeBetweenShots = 0; yield return(null); timeBetweenShots += Time.deltaTime; if (bot.CanSeeObject(target) && bot.can_shoot) { Vector3 newTargetPos = target.transform.position; Vector3 targetDir = (newTargetPos - targetPos).normalized; Vector3 aimedPos = newTargetPos; Vector3 shootDir = aimedPos - transform.position; if (newTargetPos != targetPos && (newTargetPos - targetPos).magnitude > 0.004f && Vector3.Angle(transform.forward, targetDir) % 180 > 5 /*Vector3.Distance (transform.position, newTargetPos) > 8*/) { //aimedPos = newTargetPos + targetDir * Time.deltaTime * 26 * Vector3.Distance(transform.position, newTargetPos + targetDir * Time.deltaTime * 5); //aimedPos = newTargetPos + targetDir * Time.deltaTime * 30f * Vector3.Distance(transform.position, newTargetPos /*+ targetDir * Time.deltaTime * 1.2f*/) * 0.95f; shootDir += Vector3.Distance(aimedPos, transform.position) * targetDir * Vector3.Distance(newTargetPos, targetPos) / timeBetweenShots /*Time.deltaTime /* * 0.048*/ / 22; } //shootDir = aimedPos - transform.position; Ray ray = new Ray(transform.position, shootDir); //int layerMask = LayerMask.GetMask(new string[]{ "TeamRed", "TeamBlue", "Rocket", "Flag" }); //layerMask = ~layerMask; int layerMask = 1 << 0; /*if (team.team_ID == 0) * layerMask = ~(1 << 9); * else * layerMask = ~(1 << 8);*/ RaycastHit hit; if (!Physics.SphereCast(ray, 0.75f, out hit, Vector3.Distance(transform.position, aimedPos), layerMask, QueryTriggerInteraction.Ignore) || (shootDir == aimedPos - transform.position && Vector3.Distance(transform.position, newTargetPos) <= 15) /*Vector3.Angle(transform.forward, targetDir) % 180 < 15 || Vector3.Distance (transform.position, newTargetPos) < 8*/) { if (Vector3.Angle(transform.forward, shootDir) <= 70) { bot.ShootInDirection(shootDir); GizmosService.Line(transform.position, aimedPos, 3); } } else if (hit.collider.gameObject == target) { Debug.Log("WTF MAN ???"); if (Vector3.Angle(transform.forward, shootDir) <= 70) { bot.ShootInDirection(shootDir); } } //GizmosService.Line (transform.position, aimedPos, 0.5f); foreach (BotBehaviourDeusVult ally in teamController.teamMates) { if (ally != behaviour && !ally.bot.is_dead && ally.bot.can_shoot) { //ally.ShootNow (target, newTargetPos, targetDir, Vector3.Distance (newTargetPos, targetPos) / timeBetweenShots); } } } shooter = null; }