mirror of
https://github.com/Xevion/Boids.git
synced 2025-12-06 11:14:25 -06:00
add checks for group/sep/fov checks to recreate LineRenderers
This commit is contained in:
@@ -29,6 +29,9 @@ public class Boid : MonoBehaviour {
|
||||
// Updates the rotation of the object based on the Velocity
|
||||
transform.eulerAngles = new Vector3(0, 0, Mathf.Rad2Deg * -Mathf.Atan2(_velocity.x, _velocity.y));
|
||||
|
||||
if(isFocused)
|
||||
Draw(true);
|
||||
|
||||
// Skip Flock Calculations if wrapping in progress
|
||||
if (_isWrappingX || _isWrappingY) {
|
||||
UpdateCenteringVelocity();
|
||||
@@ -72,14 +75,6 @@ public class Boid : MonoBehaviour {
|
||||
private void OnDrawGizmos() {
|
||||
// Show # of Boids in Neighborhood
|
||||
Handles.Label(transform.position, $"{_latestNeighborhoodCount}");
|
||||
|
||||
// Draw a Wire Arc visualizing FOV
|
||||
if (isFocused) {
|
||||
float angle = transform.eulerAngles.z + (_parent.boidFOV / 2f);
|
||||
Vector3 from = Quaternion.AngleAxis(angle, Vector3.up) * Vector3.forward;
|
||||
Handles.DrawWireArc(transform.position, transform.forward, from, _parent.boidFOV,
|
||||
(_parent.boidGroupRange + _parent.boidSeparationRange) / 2f);
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 DirectionFromAngle(float _angleInDeg, bool _global) {
|
||||
@@ -236,7 +231,7 @@ public class Boid : MonoBehaviour {
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
|
||||
private void Draw(bool redraw = false) {
|
||||
public void Draw(bool redraw = false) {
|
||||
if (redraw)
|
||||
foreach (Transform child in transform)
|
||||
Destroy(child.gameObject);
|
||||
@@ -292,17 +287,20 @@ public class Boid : MonoBehaviour {
|
||||
line.useWorldSpace = false;
|
||||
line.startWidth = _parent.circleWidth;
|
||||
line.endWidth = _parent.circleWidth;
|
||||
line.positionCount = vertexCount + 1;
|
||||
line.positionCount = vertexCount + 1 + 2;
|
||||
|
||||
// Calculate points for circle
|
||||
var pointCount = vertexCount + 1;
|
||||
var points = new Vector3[pointCount];
|
||||
var points = new Vector3[pointCount + 2];
|
||||
for (int i = 0; i < pointCount; i++) {
|
||||
var rad = Mathf.Deg2Rad * Mathf.LerpAngle(from, to, i / (float) pointCount);
|
||||
var rad = Mathf.Deg2Rad * (180 - Mathf.LerpAngle(from, to, i / (float) pointCount));
|
||||
// var rad = Mathf.Deg2Rad * (i * 360f / _parent.circleVertexCount);
|
||||
points[i] = new Vector3(Mathf.Sin(rad) * radius, Mathf.Cos(rad) * radius, 0);
|
||||
points[i + 1] = new Vector3(Mathf.Sin(rad) * radius, Mathf.Cos(rad) * radius, 0);
|
||||
}
|
||||
|
||||
points[0] = new Vector3(0, 0, 0);
|
||||
points[points.Length - 1] = points[0];
|
||||
|
||||
// Add points to LineRenderer
|
||||
line.SetPositions(points);
|
||||
}
|
||||
|
||||
@@ -20,15 +20,19 @@ public class BoidControllerEditor : Editor {
|
||||
}
|
||||
|
||||
// Basic Boid Controller Attributes
|
||||
controller.boidGroupRange = EditorGUILayout.Slider("Group Range", controller.boidGroupRange, 0.01f, 7.5f);
|
||||
controller.boidStartVelocity = EditorGUILayout.Slider("Start Velocity", controller.boidStartVelocity, 0.01f, 25.0f);
|
||||
EditorGUILayout.MinMaxSlider("Speed Limit", ref controller.minSpeed, ref controller.maxSpeed, 0.01f, 25f);
|
||||
// controller.minSpeed = EditorGUILayout.Slider("Minimum Speed", controller.minSpeed, 0.01f, 25.0f);
|
||||
// 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, 500f);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
controller.boidGroupRange = EditorGUILayout.Slider("Group Range", controller.boidGroupRange, 0.01f, 7.5f);
|
||||
controller.boidSeparationRange = EditorGUILayout.Slider("Separation Range", controller.boidSeparationRange, 0.01f, 5.0f);
|
||||
controller.boidFOV = EditorGUILayout.Slider("Boid FOV", controller.boidFOV, 1f, 360f);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
controller.focusedBoid.Draw(true);
|
||||
|
||||
// Boid Bias Attributes
|
||||
controller.alignmentBias = EditorGUILayout.Slider("Alignment Bias", controller.alignmentBias, 0.001f, 1.5f);
|
||||
|
||||
Reference in New Issue
Block a user