mirror of
https://github.com/Xevion/Boids.git
synced 2025-12-10 08:06:35 -06:00
Add focusing input logic
This commit is contained in:
@@ -27,10 +27,10 @@ public class Boid : MonoBehaviour {
|
||||
transform.name = $"Boid {transform.GetSiblingIndex()}"; // Name the Game Object so Boids can be tracked somewhat
|
||||
}
|
||||
|
||||
void OnDrawGizmos() {
|
||||
var transform_ = transform;
|
||||
Handles.Label(transform_.position, $"{transform_.name} {_latestNeighborhoodCount}");
|
||||
}
|
||||
// void OnDrawGizmos() {
|
||||
// var transform_ = transform;
|
||||
// Handles.Label(transform_.position, $"{transform_.name} {_latestNeighborhoodCount}");
|
||||
// }
|
||||
|
||||
void Update() {
|
||||
// Updates the rotation of the object based on the Velocity
|
||||
@@ -151,16 +151,16 @@ public class Boid : MonoBehaviour {
|
||||
|
||||
// Boundary X Force
|
||||
if (_position.x < _parent.Boundary.xMin)
|
||||
vector.x = _parent.boundaryForce;
|
||||
vector.x = _parent.boundaryForce * Mathf.InverseLerp(_parent.Boundary.xMin, _parent.Space.xMin, _position.x);
|
||||
else if (_position.x > _parent.Boundary.xMax)
|
||||
vector.x = -_parent.boundaryForce;
|
||||
vector.x = -_parent.boundaryForce * Mathf.InverseLerp(_parent.Boundary.xMax, _parent.Space.xMax, _position.x);
|
||||
|
||||
// Boundary Y Force
|
||||
if (_position.y < _parent.Boundary.yMin)
|
||||
vector.y = _parent.boundaryForce;
|
||||
vector.y = _parent.boundaryForce * Mathf.InverseLerp(_parent.Boundary.yMin, _parent.Space.yMin, _position.y);
|
||||
else if (_position.y > _parent.Boundary.yMax)
|
||||
vector.y = -_parent.boundaryForce;
|
||||
|
||||
vector.y = -_parent.boundaryForce * Mathf.InverseLerp(_parent.Boundary.yMax, _parent.Space.yMax, _position.y);
|
||||
print($"Boundary Vector: {vector}");
|
||||
return vector;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,21 @@ public class BoidController : MonoBehaviour {
|
||||
Gizmos.DrawWireCube(Cam.transform.position, new Vector3(screenWidth, screenHeight, 1));
|
||||
}
|
||||
|
||||
void Update() {
|
||||
// Focus a different Boid
|
||||
if (Input.GetKeyDown("space")) {
|
||||
// Undo previous Boid's focus
|
||||
if (focusedBoid != null) {
|
||||
var oldTriangle = focusedBoid.transform.GetComponent<Triangle>();
|
||||
oldTriangle.meshRenderer.material.color = new Color32(49, 61, 178, 255);
|
||||
}
|
||||
|
||||
focusedBoid = boids[Random.Range(0, boids.Count)];
|
||||
var triangle = focusedBoid.transform.GetComponent<Triangle>();
|
||||
triangle.meshRenderer.material.color = Color.red;
|
||||
}
|
||||
}
|
||||
|
||||
private void Start() {
|
||||
// Setup Camera
|
||||
Cam = Camera.main;
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class Triangle : MonoBehaviour {
|
||||
[NonSerialized] public Color FillColor = Color.red;
|
||||
public MeshRenderer meshRenderer;
|
||||
|
||||
private void Start () {
|
||||
// Create Vector2 vertices
|
||||
@@ -35,7 +34,7 @@ public class Triangle : MonoBehaviour {
|
||||
mesh.RecalculateBounds();
|
||||
|
||||
// Set up game object with mesh;
|
||||
var meshRenderer = gameObject.AddComponent<MeshRenderer>();
|
||||
meshRenderer = gameObject.AddComponent<MeshRenderer>();
|
||||
meshRenderer.material = (Material) Resources.Load("BoidMaterial");
|
||||
|
||||
var filter = gameObject.AddComponent<MeshFilter>();
|
||||
|
||||
Reference in New Issue
Block a user