mirror of
https://github.com/Xevion/Boids.git
synced 2025-12-07 01:14:27 -06:00
Add in the rest of the Bias/Weights/Ranges for Boid Controller
This commit is contained in:
@@ -119,7 +119,7 @@ void OnDrawGizmos() {
|
||||
Vector2 c = Vector2.zero;
|
||||
foreach (Boid boid in flock) {
|
||||
Vector2 diff = boid._position - this._position;
|
||||
if (diff.sqrMagnitude < _parent.separationRange)
|
||||
if (diff.sqrMagnitude < _parent.boidSeparationRange)
|
||||
c -= diff;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ public class BoidController : MonoBehaviour {
|
||||
public float boidGroupRange = 1.0f;
|
||||
public float boidStartVelocity = 0.005f;
|
||||
public float boidVelocityLimit = 1.0f;
|
||||
public float separationRange = 2.3f;
|
||||
public float boidSeparationRange = 2.3f;
|
||||
|
||||
// Bias changes how different rules influence individual Boids more or less
|
||||
public float separationBias = 0.05f;
|
||||
@@ -67,7 +67,6 @@ public class BoidController : MonoBehaviour {
|
||||
}
|
||||
|
||||
public void RemoveBoids(int n) {
|
||||
print($"Removing {n} boids");
|
||||
while (n-- > 0 && boids.Count >= 1) {
|
||||
int index = Random.Range(0, boids.Count - 1);
|
||||
|
||||
|
||||
@@ -10,14 +10,26 @@ public class BoidControllerEditor : Editor {
|
||||
// Boid Count update
|
||||
EditorGUI.BeginChangeCheck();
|
||||
controller.boidCount = EditorGUILayout.IntSlider("Boid Count", controller.boidCount, 1, 500);
|
||||
// Check must be performed or Boids will be added outside of Gameplay
|
||||
if (EditorGUI.EndChangeCheck() && Application.isPlaying) {
|
||||
int diff = controller.boidCount - controller.boids.Count;
|
||||
Debug.Log($"Difference: {diff}");
|
||||
if (diff > 1)
|
||||
controller.AddBoids(diff);
|
||||
else if (diff < 0)
|
||||
controller.RemoveBoids(Mathf.Abs(diff));
|
||||
}
|
||||
|
||||
// Basic Boid Controller Attributes
|
||||
controller.boidGroupRange = EditorGUILayout.Slider("Group Range", controller.boidGroupRange, 0.01f, 25.0f);
|
||||
controller.boidStartVelocity = EditorGUILayout.Slider("Start Velocity", controller.boidStartVelocity, 0.01f, 5.0f);
|
||||
controller.boidVelocityLimit = EditorGUILayout.Slider("Max Velocity", controller.boidVelocityLimit, 0.01f, 7.5f);
|
||||
controller.boidSeparationRange = EditorGUILayout.Slider("Separation Range", controller.boidSeparationRange, 0.01f, 25.0f);
|
||||
|
||||
// Boid Bias Attributes
|
||||
controller.alignmentBias = EditorGUILayout.Slider("Alignment Bias", controller.alignmentBias, 0.001f, 1.5f);
|
||||
controller.cohesionBias = EditorGUILayout.Slider("Cohesion Bias", controller.cohesionBias, 0.001f, 1.5f);
|
||||
controller.separationBias = EditorGUILayout.Slider("Separation Bias", controller.separationBias, 0.001f, 1.5f);
|
||||
|
||||
controller.localFlocks = EditorGUILayout.Toggle("Use Groups?", controller.localFlocks);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user