/// <summary> /// Flocking behaviour for constructor /// </summary> /// <param name="boid">Reference to boid</param> public FlockingBehaviour(Boid boid) { this.MaxForce = 0.05f; this.VelocityDamping = 1f; this.SeparationFactor = 1.5f; this.Boid = boid; this.environmentManager = EnvironmentManager.Shared(); }
/// <summary> /// Creates new mind object for <paramref name="boid"/> /// </summary> /// <param name="boid"></param> public Mind(Boid boid) { this.boid = boid; drinkNeed = new Need(MindState.Thirsty, Random.Range(0.1f, boid.Properties.DrinkNeedRate)); toiletNeed = new Need(MindState.Incontenent, Random.Range(0.1f, boid.Properties.ToiletNeedRate)); danceNeed = new Need(MindState.Dancey, Random.Range(0.1f, boid.Properties.DanceNeedRate)); desireNeeds(); CurrentNeed = danceNeed; startNewProcess(evaluatePriorities()); }
/// <summary> /// Is a boid within view of the current boid /// </summary> /// <param name="otherBoid">Another boid</param> /// <returns>Is <paramref name="otherBoid"/> within view</returns> private bool isWithinView(Boid otherBoid) { Vector3 boidPosition = Boid.Position; Vector3 otherBoidPosition = otherBoid.Position; float distance = Vector3.Distance(boidPosition, otherBoidPosition); return (distance < Boid.ViewingDistance) && distance != 0; }
/// <summary> /// Finds the direction to steer in relation to another <paramref name="otherBoid"/> /// </summary> /// <param name="otherBoid">Another boid</param> /// <returns>Result acceleration</returns> private Vector3 calculateSteeringDirection(Boid otherBoid) { Vector3 steeringDirection = Vector3.zero; float distance = Vector3.Distance(Boid.Position, otherBoid.Position); if (distance < Boid.MinimumDistance) { Vector3 difference = Boid.Position - otherBoid.Position; difference.Normalize(); difference /= distance; //weight by distance steeringDirection += difference; } return steeringDirection; }
/// <summary> /// Creates a new Line of sight goal seeking behaviour /// </summary> /// <param name="boid">the boid who the behaviour belongs to</param> public LineOfSightGoalSeekingBehaviour(Boid boid) : base(boid) { }