37 lines
1.3 KiB
C#
37 lines
1.3 KiB
C#
using UnityEngine;
|
|
using LinearAlgebra;
|
|
|
|
public class Swarming : Nucleus {
|
|
public Neuroid cohesion;
|
|
public Neuroid alignment;
|
|
public Neuroid avoidance;
|
|
public Neuroid boundary;
|
|
|
|
public Neuroid output;
|
|
|
|
public override Spherical outputValue { get => output.outputValue; set => output.outputValue = value; }
|
|
|
|
public Swarming(NanoBrainObj brain, Perception perception, SwarmControl sc) : base("Swarming Nucleus") {
|
|
this.cohesion = new(brain, "Cohesion") { inverse = false };
|
|
perception.SendPositions(this.cohesion, Boid.BoidType);
|
|
|
|
this.alignment = new(brain, "Alignment") { average = true };
|
|
perception.SendVelocities(this.alignment, Boid.BoidType);
|
|
|
|
this.avoidance = new(brain, "Avoidance") { inverse = true };
|
|
perception.SendPositions(this.avoidance);
|
|
|
|
this.boundary = new(brain, "Boundary");
|
|
perception.SendPositions(this.boundary, Boid.BoundaryType);
|
|
|
|
this.output = new(brain, "Swarming");
|
|
this.output.GetInputFrom(alignment, sc.alignmentForce);
|
|
this.output.GetInputFrom(cohesion, sc.cohesionForce);
|
|
this.output.GetInputFrom(avoidance, -sc.avoidanceForce);
|
|
this.output.GetInputFrom(boundary, -sc.avoidanceForce);
|
|
}
|
|
|
|
public override void AddReceiver(Nucleus receiver) {
|
|
this.output.AddReceiver(receiver);
|
|
}
|
|
} |