diff --git a/Assets/Boid.cs b/Assets/Boid.cs index 137f25d..d07e896 100644 --- a/Assets/Boid.cs +++ b/Assets/Boid.cs @@ -23,32 +23,33 @@ public class Boid : MonoBehaviour { transform.rotation = Quaternion.Euler(0, 0, Mathf.Rad2Deg * -Mathf.Atan2(velocity.x, velocity.y)); // Skip Flock Calculations if wrapping in progress - if (IsWrappingX || IsWrappingY) { - position += velocity; - return; - } - - // Acquires all Boids within the local flock - // List flock = GetFlock(parent.boids, parent.boidGroupRange); - List flock = parent.boids; - - if (flock.Count > 0) { - // Calculate all offsets and multiple by magnitudes given - Vector2 r1 = Rule1(flock) * parent.cohesionBias; - Vector2 r2 = Rule2(flock) * parent.separationBias; - Vector2 r3 = Rule3(flock) * parent.alignmentBias; - velocity += r1 + r2 + r3; - } - - // Limit the Velocity Vector to a certain Magnitude - if (velocity.magnitude > parent.boidVelocityLimit) { - velocity = (velocity / velocity.magnitude) * parent.boidVelocityLimit; + if (!IsWrappingX && !IsWrappingY) { + // Acquires all Boids within the local flock + // List flock = GetFlock(parent.boids, parent.boidGroupRange); + List flock = parent.boids; + + if (flock.Count > 0) { + // Calculate all offsets and multiple by magnitudes given + Vector2 r1 = Rule1(flock) * parent.cohesionBias; + Vector2 r2 = Rule2(flock) * parent.separationBias; + Vector2 r3 = Rule3(flock) * parent.alignmentBias; + velocity += r1 + r2 + r3; + } + + // Limit the Velocity Vector to a certain Magnitude + if (velocity.magnitude > parent.boidVelocityLimit) { + velocity = (velocity / velocity.magnitude) * parent.boidVelocityLimit; + } + } + // Update 2D and 3D transform positions based on current velocity position += velocity; transform.position = new Vector3(position.x, position.y, 0); - Wrapping(); + // If either dimension of wrapping is still unlocked, check wrapping code. + if(!IsWrappingX || !IsWrappingY) + Wrapping(); } void Wrapping() {