Vector3 Cohesion() { Vector3 steering = Vector3.zero; int total = 0; foreach (Collider2D col in Physics2D.OverlapCircleAll(VUtils.Vec3ToVec2(transform.position), SeperationRadius)) { if (col.gameObject != gameObject) { AIBoids ai = col.gameObject.GetComponent <AIBoids>(); if (ai) { Vector3 line_to_other = col.transform.position - transform.position; steering += line_to_other; total++; } } } if (total > 0) { steering /= total; // steering -= VUtils.Vec2ToVec3(rb.velocity); // steering = Mathf.Min(steering, MaxForce); } return(steering.normalized); }
// Start is called before the first frame update void Start() { attack = GetComponent <AISimpleAttack>(); movement = GetComponent <AIBoids>(); col = GetComponent <BoxCollider2D>(); attack.enabled = false; movement.enabled = false; col.isTrigger = true; h = GetComponent <Health>(); }
// Start is called before the first frame update void Start() { toast = GameObject.FindGameObjectWithTag("Toast").GetComponent <Toast>(); foreach (float val in enemy_weights) { total += val; } remainingEnemies = 0; spawnPoint = transform.Find("SpawnPoint"); foreach (Collider2D col in Physics2D.OverlapCircleAll(VUtils.Vec3ToVec2(transform.position), 10)) { AIBoids ai = col.gameObject.GetComponent <AIBoids>(); if (ai) { remainingEnemies++; } } }