mirror of
https://github.com/Xevion/Boids.git
synced 2025-12-15 02:11:07 -06:00
implemented FOV checks, back to foreach loop, BoidController sliders
This commit is contained in:
@@ -169,7 +169,23 @@ public class Boid : MonoBehaviour {
|
||||
|
||||
// Returns a list of boids within a certain radius of the Boid, representing it's local 'flock'
|
||||
private List<Boid> GetFlock(List<Boid> boids, float radius) {
|
||||
return boids.Where(boid => boid != this && Vector2.Distance(this._position, boid._position) <= radius).ToList();
|
||||
List<Boid> flock = new List<Boid>();
|
||||
|
||||
foreach (Boid boid in boids) {
|
||||
if (boid == this || Vector2.Distance(this._position, boid._position) > radius)
|
||||
continue;
|
||||
|
||||
if (_parent.enableFOVChecks) {
|
||||
float angle1 = Mathf.Rad2Deg * -Mathf.Atan2(_velocity.x, _velocity.y);
|
||||
float angle2 = Mathf.Rad2Deg * -Mathf.Atan2(boid._velocity.x, boid._velocity.y);
|
||||
if (Mathf.Abs(angle2 - angle1) > _parent.boidFOV / 2)
|
||||
continue;
|
||||
}
|
||||
|
||||
flock.Add(boid);
|
||||
}
|
||||
|
||||
return flock;
|
||||
}
|
||||
|
||||
// Sets up a Boid to be 'Focused', adds Circles around object and changes color
|
||||
|
||||
@@ -29,6 +29,7 @@ public class BoidController : MonoBehaviour {
|
||||
[SerializeField] public bool enableAlignment = true;
|
||||
[SerializeField] public bool enableCohesion = true;
|
||||
[SerializeField] public bool enableBoundary = true;
|
||||
[SerializeField] public bool enableFOVChecks = true;
|
||||
|
||||
[SerializeField] public float boidSeparationRange = 2.3f; // Boid Separation rule's activation distance
|
||||
[SerializeField] public float boundaryForce = 10f; // The force applied when a Boid hits the boundary
|
||||
@@ -37,6 +38,7 @@ public class BoidController : MonoBehaviour {
|
||||
[SerializeField] public int circleVertexCount = 40; // The number of vertices for circles displayed
|
||||
[SerializeField] public float circleWidth = 0.1f; // Width of circle
|
||||
[SerializeField] public float maxSteerForce = 10f;
|
||||
[SerializeField] public float boidFOV = 160;
|
||||
|
||||
|
||||
public Boid focusedBoid; // A focused Boid has special rendering
|
||||
|
||||
@@ -26,12 +26,13 @@ public class BoidControllerEditor : Editor {
|
||||
controller.maxSpeed = EditorGUILayout.Slider("Maximum Speed", controller.maxSpeed, 0.01f, 25.0f);
|
||||
controller.boidSeparationRange = EditorGUILayout.Slider("Separation Range", controller.boidSeparationRange, 0.01f, 5.0f);
|
||||
controller.boundaryForce = EditorGUILayout.Slider("Boundary Force", controller.boundaryForce, 0.25f, 50f);
|
||||
controller.maxSteerForce = EditorGUILayout.Slider("Max Steer Force", controller.maxSteerForce, 1f, 200f);
|
||||
|
||||
controller.maxSteerForce = EditorGUILayout.Slider("Max Steer Force", controller.maxSteerForce, 1f, 500f);
|
||||
controller.boidFOV = EditorGUILayout.Slider("Boid FOV", controller.boidFOV, 1f, 360f);
|
||||
|
||||
// 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.separationBias = EditorGUILayout.Slider("Separation Bias", controller.separationBias, 0.001f, 2.5f);
|
||||
controller.boundaryBias = EditorGUILayout.Slider("Boundary Bias", controller.boundaryBias, 0.01f, 1.5f);
|
||||
|
||||
controller.localFlocks = EditorGUILayout.Toggle("Use Groups?", controller.localFlocks);
|
||||
@@ -41,6 +42,7 @@ public class BoidControllerEditor : Editor {
|
||||
controller.enableCohesion = EditorGUILayout.Toggle("Enable Cohesion?", controller.enableCohesion);
|
||||
controller.enableSeparation = EditorGUILayout.Toggle("Enable Separation?", controller.enableSeparation);
|
||||
controller.enableBoundary = EditorGUILayout.Toggle("Enable Boundary?", controller.enableBoundary);
|
||||
controller.enableFOVChecks = EditorGUILayout.Toggle("Enable FOV?", controller.enableFOVChecks);
|
||||
|
||||
// Boid Rendering
|
||||
controller.circleVertexCount = EditorGUILayout.IntSlider("Circle Vertex Count", controller.circleVertexCount, 4, 360);
|
||||
|
||||
Reference in New Issue
Block a user