neighbor count label gizmo, attempt at arc FOV gizmo, make min/max speed sliders into single min/max slider

This commit is contained in:
Xevion
2020-05-27 19:18:05 -05:00
parent 74ddf684a9
commit 784d498a52
4 changed files with 40 additions and 19 deletions
+13 -11
View File
@@ -1252,27 +1252,29 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 7d72224fef7a4fb4a998b0980fe0eb77, type: 3}
m_Name:
m_EditorClassIdentifier:
boidCount: 372
boidGroupRange: 3.03
boidCount: 244
boidGroupRange: 3.29
boidStartVelocity: 14.8
minSpeed: 12
maxSpeed: 12
minSpeed: 9.225757
maxSpeed: 9.225757
globalBias: 1
separationBias: 1.5
alignmentBias: 0.517
cohesionBias: 0.451
boundaryBias: 1.492
separationBias: 1.95
alignmentBias: 0.288
cohesionBias: 0.296
boundaryBias: 1.5
enableSeparation: 1
enableAlignment: 1
enableCohesion: 1
enableBoundary: 1
boidSeparationRange: 2.3
boundaryForce: 7.6
enableFOVChecks: 1
boidSeparationRange: 1.4
boundaryForce: 50
localFlocks: 1
edgeWrapping: 1
circleVertexCount: 360
circleWidth: 0.1
maxSteerForce: 138
maxSteerForce: 383
boidFOV: 297
focusedBoid: {fileID: 0}
boidObject: {fileID: 1737515784064720040, guid: 23e1eaaf69d4ef342ac3ef9590f6c642,
type: 3}
+24 -5
View File
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using UnityEditor;
using UnityEngine;
using Random = UnityEngine.Random;
// Boids are represented by a moving, rotating triangle.
// Boids should communicate with sibling Boids
@@ -29,7 +27,7 @@ public class Boid : MonoBehaviour {
private void Update() {
// Updates the rotation of the object based on the Velocity
transform.rotation = Quaternion.Euler(0, 0, Mathf.Rad2Deg * -Mathf.Atan2(_velocity.x, _velocity.y));
transform.eulerAngles = new Vector3(0, 0, Mathf.Rad2Deg * -Mathf.Atan2(_velocity.x, _velocity.y));
// Skip Flock Calculations if wrapping in progress
if (_isWrappingX || _isWrappingY) {
@@ -71,6 +69,27 @@ public class Boid : MonoBehaviour {
Wrapping();
}
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) {
if (_global == false) {
_angleInDeg += transform.eulerAngles.z;
}
return new Vector3(Mathf.Sin(_angleInDeg * Mathf.Deg2Rad), Mathf.Cos(_angleInDeg * Mathf.Deg2Rad), 0);
}
private Vector2 SteerTowards(Vector2 vector) {
Vector2 v = vector.normalized * _parent.maxSpeed - _velocity;
return Vector2.ClampMagnitude(v, _parent.maxSteerForce);
@@ -170,7 +189,7 @@ 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) {
List<Boid> flock = new List<Boid>();
foreach (Boid boid in boids) {
if (boid == this || Vector2.Distance(this._position, boid._position) > radius)
continue;
-1
View File
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using Debug = System.Diagnostics.Debug;
using Random = UnityEngine.Random;
public class BoidController : MonoBehaviour {
+3 -2
View File
@@ -22,8 +22,9 @@ 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);
controller.minSpeed = EditorGUILayout.Slider("Minimum Speed", controller.minSpeed, 0.01f, 25.0f);
controller.maxSpeed = EditorGUILayout.Slider("Maximum Speed", controller.maxSpeed, 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);