mirror of
https://github.com/Xevion/Boids.git
synced 2025-12-12 03:09:22 -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;
|
Vector2 c = Vector2.zero;
|
||||||
foreach (Boid boid in flock) {
|
foreach (Boid boid in flock) {
|
||||||
Vector2 diff = boid._position - this._position;
|
Vector2 diff = boid._position - this._position;
|
||||||
if (diff.sqrMagnitude < _parent.separationRange)
|
if (diff.sqrMagnitude < _parent.boidSeparationRange)
|
||||||
c -= diff;
|
c -= diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public class BoidController : MonoBehaviour {
|
|||||||
public float boidGroupRange = 1.0f;
|
public float boidGroupRange = 1.0f;
|
||||||
public float boidStartVelocity = 0.005f;
|
public float boidStartVelocity = 0.005f;
|
||||||
public float boidVelocityLimit = 1.0f;
|
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
|
// Bias changes how different rules influence individual Boids more or less
|
||||||
public float separationBias = 0.05f;
|
public float separationBias = 0.05f;
|
||||||
@@ -67,7 +67,6 @@ public class BoidController : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveBoids(int n) {
|
public void RemoveBoids(int n) {
|
||||||
print($"Removing {n} boids");
|
|
||||||
while (n-- > 0 && boids.Count >= 1) {
|
while (n-- > 0 && boids.Count >= 1) {
|
||||||
int index = Random.Range(0, boids.Count - 1);
|
int index = Random.Range(0, boids.Count - 1);
|
||||||
|
|
||||||
|
|||||||
@@ -10,14 +10,26 @@ public class BoidControllerEditor : Editor {
|
|||||||
// Boid Count update
|
// Boid Count update
|
||||||
EditorGUI.BeginChangeCheck();
|
EditorGUI.BeginChangeCheck();
|
||||||
controller.boidCount = EditorGUILayout.IntSlider("Boid Count", controller.boidCount, 1, 500);
|
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) {
|
if (EditorGUI.EndChangeCheck() && Application.isPlaying) {
|
||||||
int diff = controller.boidCount - controller.boids.Count;
|
int diff = controller.boidCount - controller.boids.Count;
|
||||||
Debug.Log($"Difference: {diff}");
|
|
||||||
if (diff > 1)
|
if (diff > 1)
|
||||||
controller.AddBoids(diff);
|
controller.AddBoids(diff);
|
||||||
else if (diff < 0)
|
else if (diff < 0)
|
||||||
controller.RemoveBoids(Mathf.Abs(diff));
|
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