mirror of
https://github.com/Xevion/Boids.git
synced 2025-12-14 04:11:04 -06:00
Major work with new Boid prefrab, configuring rules and attempt at camera wrapping - getting close to working prototype
This commit is contained in:
@@ -1,34 +1,51 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class BoidController : MonoBehaviour {
|
||||
// Controller Attributes
|
||||
public Rect space;
|
||||
|
||||
public Rect space = new Rect(new Vector2(0, 0), new Vector2(24000, 14000));
|
||||
|
||||
// Swarm Attributes
|
||||
public int boidCount = 1000;
|
||||
public int boidCount = 50;
|
||||
public float boidGroupRange = 1.0f;
|
||||
|
||||
|
||||
// Bias changes how different rules influence individual Boids more or less
|
||||
public float separationBias = 1.0f;
|
||||
public float alignmentBias = 1.0f;
|
||||
public float cohesionBias = 1.0f;
|
||||
|
||||
private List<Boid> _boids = new List<Boid>();
|
||||
|
||||
|
||||
public GameObject boidObject;
|
||||
|
||||
public List<Boid> boids = new List<Boid>();
|
||||
|
||||
private void OnDrawGizmos() {
|
||||
Gizmos.DrawWireCube(space.center, space.size);
|
||||
}
|
||||
|
||||
void Start() {
|
||||
for(int i = 0; i < boidCount; i++)
|
||||
_boids.Add(new Boid(Vector2.zero, new Vector2(1, 1)));
|
||||
for (int i = 0; i < boidCount; i++) {
|
||||
var position = new Vector2(Random.Range(-15, 15), Random.Range(-15, 15));
|
||||
var boid = Instantiate(boidObject, position, Quaternion.identity);
|
||||
|
||||
boid.transform.parent = transform;
|
||||
boids.Add(boid.GetComponent<Boid>());
|
||||
boids[boids.Count - 1].position = position;
|
||||
}
|
||||
}
|
||||
|
||||
void Update() {
|
||||
float[] magnitudes = new float[] {cohesionBias, separationBias, alignmentBias};
|
||||
// foreach (Boid boid in boids) {
|
||||
// if (!space.Contains(boid.position))
|
||||
// boid.position = transform.position;
|
||||
// }
|
||||
|
||||
float[] magnitudes = {cohesionBias, separationBias, alignmentBias};
|
||||
// Update all Boid positions
|
||||
foreach (Boid boid in _boids) {
|
||||
boid.SetPosition(boid.NextPosition(_boids, magnitudes));
|
||||
foreach (Boid boid in boids) {
|
||||
Vector2 next = boid.NextPosition(boids, magnitudes);
|
||||
boid.position = next;
|
||||
boid.transform.position = new Vector3(next.x, next.y, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user