//Uses the various Movement Behaviors to calculate the vector to // determine the next position of the agent private void CalcSteeringForce() { steeringForce = Vector3.zero; for (int i = 0; i < gameManager.Werewolves.Count; i++) { float wDist = Vector3.Distance(this.transform.position, gameManager.Werewolves[i].transform.position); if (wDist < 20) { if (wDist < 5) { steeringForce += steering.Flee(gameManager.Werewolves[i].transform.position); if (leaderFollowBool == true) { gameManager.Followers.Remove(this); } leaderFollowBool = false; } else { steeringForce += steering.Evasion(gameManager.Werewolves[i].transform.position + gameManager.Werewolves[i].transform.forward); } } else if (Vector3.Distance(this.transform.position, gameManager.Mayor.transform.position) < 40 && leaderFollowBool == false) { gameManager.Followers.Add(this); steeringForce += 10 * leaderFollow(); steeringForce += gameManager.separationWt * Separation(); steeringForce += gameManager.cohesionWt * Cohesion(); } else if (leaderFollowBool == true) { steeringForce += 15 * leaderFollow(); steeringForce += gameManager.separationWt * Separation(); steeringForce += gameManager.cohesionWt * Cohesion(); } else { steeringForce += 2 * wander(); } } steeringForce += gameManager.inBoundsWt * StayInBounds(200, new Vector3(469, 0, 454)); //avoid close obstacles for (int i = 0; i < gameManager.Obstacles.Length; i++) { if (Vector3.Distance(this.transform.position, gameManager.Obstacles[i].transform.position) < 60) { //steeringForce += steering.AvoidObstacle(gameManager.Obstacles[i], gameManager.avoidDist); } } }
private void CalcSteeringForce() { steeringForce = Vector3.zero; //Keeps werewolves away from Villager Spawn point steeringForce += gameManager.avoidWt * steering.AvoidObstacle(respawnPont, 100f); float mayDist = Vector3.Distance(this.transform.position, gameManager.Mayor.transform.position); //Choose new villager to chase (closest villager) target = gameManager.Villagers[0]; findTarget(); float tarDist = Vector3.Distance(this.transform.position, target.transform.position); if (tarDist > 30) { steeringForce += 10 * steering.Pursuit(target.transform.forward + target.transform.position); } else { steeringForce += 6 * steering.Seek(target); } if (mayDist < 20) { steeringForce += 20 * steering.Flee(gameManager.Mayor); } else { steeringForce += 5 * steering.Evasion(gameManager.Mayor.transform.forward + gameManager.Mayor.transform.position); } //avoid close obstacles for (int i = 0; i < gameManager.Obstacles.Length; i++) { if (Vector3.Distance(this.transform.position, gameManager.Obstacles[i].transform.position) < 60) { steeringForce += gameManager.avoidWt * steering.AvoidObstacle(gameManager.Obstacles[i], gameManager.avoidDist); } } }