private void GoTowardsEnemy() { float distanceToClosestEnemy = Mathf.Infinity; // Debug.Log(TargetingArea.instance); List <AIDriver> Enemies = RM.InRange; AIDriver closestEnemy = null; //go through the list of enemys to find the closest en //Enemy[] allEnemies = GameObject.FindObjectsOfType<Enemy>(); foreach (AIDriver currentEnemy in Enemies) { if (currentEnemy != null) { float distanceToEnemy = (currentEnemy.transform.position - this.transform.position).sqrMagnitude; if (distanceToEnemy < distanceToClosestEnemy) { distanceToClosestEnemy = distanceToEnemy; closestEnemy = currentEnemy; } } } if (closestEnemy != null) { lookOnLook = Quaternion.LookRotation(closestEnemy.transform.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, lookOnLook, Time.deltaTime * turnSpeed); if (boostTime) { rb.AddForce(transform.forward * boost, ForceMode.Force); } } }
void FixedUpdate() { GameObject newFollowing = null; if (CheckIfFollowingDriver(out newFollowing)) { if (following != newFollowing && newFollowing != null) { if (followingAiDriver != null) { followingAiDriver.aiSettings.targetSqrSpeed = targetSpeedbefore; } following = newFollowing; followingAiDriver = following.GetComponent <AIDriver>(); targetSpeedbefore = followingAiDriver.aiSettings.targetSqrSpeed; SetDraftingMarker(); } ApplyDrag(); } else { following = null; followingIndicator.SetActive(false); } }
void Awake() { IEngine solidFuel = new SolidFuelEngine(); IDriver humanDriver = new HumanDriver(); SaturnV_player.SetEngine(solidFuel); SaturnV_player.SetDriver(humanDriver); SaturnV_player.StartEngine(); IEngine hybridFuel = new HybridEngine(); IDriver ET = new AIDriver(); Mercury_AI.SetEngine(hybridFuel); Mercury_AI.SetDriver(ET); Mercury_AI.StartEngine(); IEngine liquidFuel = new LiquidFuelEngine(); IDriver ElonMusk = new AIDriver(); FalconHeavy_AI.SetEngine(liquidFuel); FalconHeavy_AI.SetDriver(ElonMusk); FalconHeavy_AI.StartEngine(); IEngine ionEngine = new IonEngine(); IDriver AI = new AIDriver(); Antares_AI.SetEngine(ionEngine); Antares_AI.SetDriver(AI); Antares_AI.StartEngine(); }
public override void GetEnemies(AIDriver driver, int maxEnemies, ICollection <ShipController> outEnemiesResult) { if (driver.ship.offenders.Count > 0) { outEnemiesResult.Add(driver.ship.offenders.WithMin(s => (s.ship.tempTransform.position - driver.shipPosition).sqrMagnitude).ship); } }
// Start is called before the first frame update void Awake() { IEngine jetEngine = new JetEngine(); IDriver human = new HumanDriver(); playerBike.SetEngine(jetEngine); playerBike.SetDriver(human); playerBike.StartEngine(); IEngine nitroEngine = new NitroEngine(); IDriver aiOne = new AIDriver(); AIBikeOne.SetEngine(nitroEngine); AIBikeOne.SetDriver(aiOne); AIBikeOne.StartEngine(); IEngine warpEngine = new WarpEngine(); IDriver aiTwo = new AIDriver(); AIBikeTwo.SetEngine(warpEngine); AIBikeTwo.SetDriver(aiTwo); AIBikeTwo.StartEngine(); IEngine hyperDrive = new Hyperdrive(); IDriver aiThree = new AIDriver(); AIBikeThree.SetEngine(hyperDrive); AIBikeThree.SetDriver(aiThree); AIBikeThree.StartEngine(); }
protected override float GetGoalWeight(AIDriver driver) { float r = 0; var ships = driver.enemiesAround; var count = ships.Count; int wShipClass = driver.shipClass * 2; if (count >= wShipClass) { return(1f); } int n = count - (count % 4); int i = 0; for (; i < n; i++) { r += ships[i].shipClass; r += ships[i++].shipClass; r += ships[i++].shipClass; r += ships[i++].shipClass; if (r >= wShipClass) { return(1f); } } for (; i < count; i++) { r += ships[i].shipClass; } r /= wShipClass; return(r > 1f ? 1f : r); }
public override void GetEnemies(AIDriver driver, int maxEnemies, ICollection <ShipController> outEnemiesResult) { var ships = driver.enemiesAround; int count = ships.Count; if (count == 0) { return; } ShipController nearestEnemy = ships[0]; float sqrDistance = (driver.ship.tempTransform.position - nearestEnemy.tempTransform.position).sqrMagnitude / (nearestEnemy.shipClass * nearestEnemy.shipClass); ShipController ship; int i = 1; float tempSqrDistance; for (; i < count; i++) { ship = ships[i]; if (ship.team.team != driver.shipTeam.team) { tempSqrDistance = (driver.ship.tempTransform.position - ship.tempTransform.position).sqrMagnitude / (ship.shipClass * ship.shipClass); if (tempSqrDistance < sqrDistance) { nearestEnemy = ship; sqrDistance = tempSqrDistance; } } } // adding only one enemy outEnemiesResult.Add(nearestEnemy); }
void SpawnPolice() { Debug.Log("Police spawned"); police = (AIDriver)Instantiate(PoliceVehicle, Vector3.one * -50f, Quaternion.identity).GetComponent <AIDriver>(); police.InitPolice(); }
void SpawnPC() { AIDriver en = (AIDriver)Instantiate(othervehicle, Vector3.one * -50f, Quaternion.identity).GetComponent <AIDriver>(); Enemies.Add(en); en.Init(OnComing); OnComing = !OnComing; }
public void Init(AIDriver driver) { LastPriorityCalc = 0; Driver = driver; Pawn = driver.Pawn as StatePawn; OnInit(); }
void Start() { if (!Driver) { Driver = GetComponent <AIDriver>(); } DeadTrigger.enabled = false; }
public override void GetEnemies(AIDriver driver, int maxEnemies, ICollection <ShipController> outEnemiesResult) { var offenders = goal.goal.offenders.Where(t => t.ship.team != driver.ship.team).Cache(); if (offenders.Count > 0) { outEnemiesResult.Add(offenders.WithMin(o => (o.ship.tempTransform.position - driver.shipPosition).sqrMagnitude).ship); } }
void SpawnPC() { AIDriver en = (AIDriver)Instantiate(othervehicle, Vector3.one * -50f, Quaternion.identity).GetComponent <AIDriver>(); en.Init(toggle); Enemies.Add(en); toggle = !toggle; }
public void OnAIKilled(AIDriver driver) { var asPlay = CurrentState as GamePlay; if (asPlay) { asPlay.OnAIKilled(driver); } }
public void OnAIKilled(AIDriver driver) { MainGame.Instance.Controllers.Unregister(driver); foreach (var collider in driver.GetComponentsInChildren <Collider>()) { collider.enabled = false; } driver.GetComponent <DeadBody>().JustDied(); }
public void RemoveDriver(AIDriver driver, string s = null) { // if(s != null) // Debug.Log(s); if (Enemies.Contains(driver) && !EnemiesToRemove.Contains(driver)) { EnemiesToRemove.Add(driver); } // Debug.Log(driver); }
private void Awake() { IDriver driver = new AIDriver(); airplane.SetDriver(driver); airplane.StartEngine(); //currentState = new NormalEnemyState(); TriggerFightState(); }
protected override void OnBegin() { if (!Driver) { Driver = GetComponentInParent <AIDriver>(); } if (Driver && Driver.CurrentEnemy) { Driver.CurrentEnemy.Hurt(Dmg); OnAttack.Invoke(); } }
public override bool GetMovePoint(AIDriver driver, out Vector3 result) { if (driver.enemy != null) { result = driver.enemy.tempTransform.position; return(true); } else { result = Vector3.zero; return(false); } }
void SpawnPC() { int i = Random.Range(0, CarPre.Count); othervehicle = CarPre[i]; AIDriver en = (AIDriver)Instantiate(othervehicle, Vector3.one * -50f, Quaternion.identity).GetComponent <AIDriver>(); en.gameObject.transform.localScale = Vector3.one * .75f; Enemies.Add(en); en.Init(OnComing); OnComing = !OnComing; }
public override bool GetMovePoint(AIDriver driver, out Vector3 result) { if (driver.ship == goal.target) { result = goal.to.tempTransform.position; return(true); } else { result = goal.target.tempTransform.position; return(true); } }
void Update() { if (!Application.isPlaying) { aiDriver = gameObject.GetComponent("AIDriver") as AIDriver; Transform colliderBottom = transform.FindChild("Colliders/ColliderBottom"); aiDriver.oASideOffset = Mathf.Abs(colliderBottom.localPosition.x) + colliderBottom.localScale.x / 2 + 0.1f; Vector3 vpPos = aiDriver.viewPoint.localPosition; vpPos.z = colliderBottom.localPosition.z + colliderBottom.localScale.z / 2 + 0.1f; vpPos.x = 0; aiDriver.viewPoint.localPosition = vpPos; } }
public void Throw(Vector3 power) { if (!Driver) { Driver = GetComponent <AIDriver>(); } WasThrown = true; EnsureDeadCollider(); EnableRagdoll(); Driver.Pawn.Body.AddForce(power, ForceMode.Impulse); }
void Start() { nPCspawner = GetComponent <NPCspawner>(); player = nPCspawner.player; playerMovement = player.GetComponent <PlayerMovement>(); aiDriverList = new List <AIDriver>(); foreach (GameObject item in nPCspawner.npcList) { AIDriver currentDriver = item.GetComponent <AIDriver>(); aiDriverList.Add(currentDriver); item.GetComponent <Respawn>().AddFirstToRespawnAction(() => { currentDriver.WaypointNodeID = playerMovement.ClosestNode + spawnNodeDistance; }); } }
public override bool GetMovePoint(AIDriver driver, out Vector3 result) { var offenders = goal.goal.offenders.Where(s => s.ship.team != driver.ship.team).Cache(); if (offenders.Count > 0) { result = offenders.WithMin(o => (o.ship.tempTransform.position - driver.shipPosition).sqrMagnitude).ship.tempTransform.position - driver.shipPosition; return(true); } else { result = default(Vector3); return(false); } }
protected override float GetGoalWeight(AIDriver driver) { float r = 0; var ships = driver.ship.offenders; var count = ships.Count; for (int i = 0; i < count; i++) { r += ships[i].ship.shipClass; } r *= (1f - driver.ship.health * .5f) / (driver.shipClass * 2); return(r > 1f ? 1f : r); }
public override bool GetMovePoint(AIDriver driver, out Vector3 result) { if (driver.ship.offenders.Count > 0) { Vector3 v = Vector3.zero; foreach (var o in driver.ship.offenders) { v += (o.ship.tempTransform.position - driver.ship.tempTransform.position); } result = driver.ship.tempTransform.position + Vector3.Cross(driver.ship.tempTransform.forward, v); return(true); } else { result = default(Vector3); return(false); } }
public void OnDrawGizmos() { if (!Application.isPlaying || show) { aiDriver = gameObject.GetComponent("AIDriver") as AIDriver; if (aiDriver.useObstacleAvoidance) { Vector3 viewPointLeft; Vector3 viewPointRight; Vector3 forwardDirection = aiDriver.viewPoint.TransformDirection(Vector3.forward * aiDriver.oADistance); Vector3 centerPointL = transform.position + transform.TransformDirection(Vector3.left * aiDriver.oASideOffset); centerPointL.y = aiDriver.viewPoint.position.y; Vector3 centerPointR = transform.position + transform.TransformDirection(Vector3.right * aiDriver.oASideOffset); centerPointR.y = aiDriver.viewPoint.position.y; viewPointLeft = aiDriver.viewPoint.transform.position; viewPointRight = aiDriver.viewPoint.transform.position; viewPointLeft += aiDriver.viewPoint.TransformDirection((Vector3.right * aiDriver.flWheel.localPosition.x)); viewPointRight += aiDriver.viewPoint.TransformDirection((Vector3.right * aiDriver.frWheel.localPosition.x)); float obstacleAvoidanceWidth = aiDriver.oAWidth; Vector3 leftDirection = aiDriver.viewPoint.TransformDirection((Vector3.left * obstacleAvoidanceWidth) + (Vector3.forward * aiDriver.oADistance)); Vector3 rightDirection = aiDriver.viewPoint.TransformDirection((Vector3.right * obstacleAvoidanceWidth) + (Vector3.forward * aiDriver.oADistance)); Vector3 leftSide = aiDriver.viewPoint.TransformDirection(Vector3.left * aiDriver.oASideDistance); Vector3 rightSide = aiDriver.viewPoint.TransformDirection(Vector3.right * aiDriver.oASideDistance); Debug.DrawRay(viewPointLeft, leftDirection, Color.cyan); Debug.DrawRay(viewPointRight, rightDirection, Color.cyan); Debug.DrawRay(aiDriver.viewPoint.position, forwardDirection, Color.green); Debug.DrawRay(viewPointLeft, forwardDirection, Color.green); Debug.DrawRay(viewPointRight, forwardDirection, Color.green); Debug.DrawRay(centerPointL, leftSide, Color.magenta); Debug.DrawRay(centerPointR, rightSide, Color.magenta); } } }
protected override float GetGoalWeight(AIDriver driver) { return(goal.goal.offenders.Count > 0 ? 1f : 0f); }
protected override float GetGoalWeight(AIDriver driver) { return(1f); }
public override bool GetMovePoint(AIDriver driver, out Vector3 result) { result = goal.goal.tempTransform.position - driver.shipPosition; return(true); }
public override void GetEnemies(AIDriver driver, int maxEnemies, ICollection <ShipController> outEnemiesResult) { outEnemiesResult.Add(goal.goal); }
void Start() { //wir machen dies in der Start-Routine, weil wir im AIDriver-Skript erst in der Awake-Fkt die Waypoints zuweisen //Um sicherzugehen, dass die Waypoints auch gefunden und der List zugewiesen wurde, weisen wir dies deshalb erst hier zu! aiDriverScript = gameObject.GetComponent("AIDriver") as AIDriver; waypoints = aiDriverScript.waypoints; }