mirror of
https://github.com/Xevion/Boids.git
synced 2025-12-15 00:11:07 -06:00
fix access modifiers, start and update functions
This commit is contained in:
@@ -5,7 +5,7 @@ public class Boid {
|
|||||||
private Vector2 _position;
|
private Vector2 _position;
|
||||||
private Vector2 _velocity;
|
private Vector2 _velocity;
|
||||||
|
|
||||||
Boid(Vector2 position, Vector2 velocity) {
|
public Boid(Vector2 position, Vector2 velocity) {
|
||||||
_position = position;
|
_position = position;
|
||||||
_velocity = velocity;
|
_velocity = velocity;
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,7 @@ public class Boid {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns the next position the Boid will be moving to
|
// Returns the next position the Boid will be moving to
|
||||||
Vector2 NextPosition(List<Boid> boids, float[] magnitudes) {
|
public Vector2 NextPosition(List<Boid> boids, float[] magnitudes) {
|
||||||
// Find the local flock
|
// Find the local flock
|
||||||
List<Boid> flock = GetFlock(boids, 5);
|
List<Boid> flock = GetFlock(boids, 5);
|
||||||
|
|
||||||
|
|||||||
@@ -18,11 +18,17 @@ public class BoidController : MonoBehaviour {
|
|||||||
private List<Boid> _boids = new List<Boid>();
|
private List<Boid> _boids = new List<Boid>();
|
||||||
|
|
||||||
void Start() {
|
void Start() {
|
||||||
|
for(int i = 0; i < boidCount; i++)
|
||||||
|
_boids.Add(new Boid(Vector2.zero, new Vector2(1, 1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update() {
|
||||||
|
float[] magnitudes = new float[] {cohesionBias, separationBias, alignmentBias};
|
||||||
|
// Update all Boid positions
|
||||||
|
foreach (Boid boid in _boids) {
|
||||||
|
boid.SetPosition(boid.NextPosition(_boids, magnitudes));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user