Example #1
0
        /// <summary>
        /// Vector away from the average heading of the target group.
        /// We use a timer to track how long we have been attempting an attack, and based on this we
        /// decide how strongly we should be withdrawing.
        /// </summary>
        private Vector3 CalculateAttemptWithdrawal(List <Boid> boids, float currentWithdrawalWeight)
        {
            if (boids == null || boids.Count == 0)
            {
                return(Vector3.zero);
            }

            return((Position - BoidUtility.GetAveragePosition(boids)).normalized * currentWithdrawalWeight);
        }
Example #2
0
        /// <summary>
        /// Vector towards the the average position of the fringes.
        /// By directing to the position of the fringe group, we act to cut off
        /// the target group from reconnecting with the main flock.
        /// </summary>
        private Vector3 CalculateFlockSeparation(HashSet <Boid> fringes, float currentWithdrawalWeight)
        {
            if (fringes == null || fringes.Count == 0)
            {
                return(Vector3.zero);
            }

            return((BoidUtility.GetAveragePosition(fringes) - Position).normalized * (1f - currentWithdrawalWeight));
        }
Example #3
0
        /// <summary>
        /// Vector towards the average position of the targets.
        /// By directing to the center of the group, we can achieve maximum
        /// fragmentation of the group and hopefully futher isolate target boids.
        /// </summary>
        private Vector3 CalculateGroupDisruption(HashSet <Boid> targets, float currentWithdrawalWeight)
        {
            if (targets == null || targets.Count == 0)
            {
                return(Vector3.zero);
            }

            return((BoidUtility.GetAveragePosition(targets) - Position).normalized * (1f - currentWithdrawalWeight));
        }
Example #4
0
        private void OnDrawGizmosSelected()
        {
            if (!showDebug)
            {
                return;
            }

            //Targets
            Gizmos.color = Color.red;

            ///draw average position of target group
            var avgTargetPos = BoidUtility.GetAveragePosition(targetGroup);

            if (avgTargetPos != Vector3.zero)
            {
                Gizmos.DrawSphere(avgTargetPos, 0.33f);
            }

            ///draw position of each target
            foreach (var b in targetGroup)
            {
                Gizmos.DrawWireSphere(b.Position, 0.25f);
            }

            //Fringes
            Gizmos.color = Color.yellow;

            ///draw average position of fringe group
            var avgFringePos = BoidUtility.GetAveragePosition(fringeGroup);

            if (avgFringePos != Vector3.zero)
            {
                Gizmos.DrawSphere(avgFringePos, 0.33f);
            }

            ///draw position of each fringe boid
            foreach (var b in fringeGroup)
            {
                Gizmos.DrawWireSphere(b.Position, 0.25f);
            }

            //Withdrawal
            float currentWithdrawlWeighting = Mathf.InverseLerp(withdrawalStartTime, withdrawalEndTime, timeSinceAttackStarted);

            if (currentWithdrawlWeighting <= 0.5f)
            {
                Gizmos.color = Color.Lerp(Color.green, Color.yellow, currentWithdrawlWeighting * 2);
            }
            else
            {
                Gizmos.color = Color.Lerp(Color.yellow, Color.red, 2 * currentWithdrawlWeighting - 1f);
            }

            Gizmos.DrawCube(Position + Vector3.up * 0.2f, Vector3.one * 0.4f);

            var separation   = flockSeparation * separationWeightNorm;
            var disruption   = groupDisruption * disruptionWeightNorm;
            var eagerness    = attackEagerness * eagernessWeightNorm;
            var withdrawal   = attemptWithdrawal * withdrawalWeightNorm;
            var independence = huntIndependence * independenceWeightNorm;

            Gizmos.color = Color.white;
            Gizmos.DrawLine(Position, Position + separation * 5);
            Gizmos.color = Color.cyan;
            Gizmos.DrawLine(Position, Position + disruption * 5);
            Gizmos.color = Color.magenta;
            Gizmos.DrawLine(Position, Position + eagerness * 5);
            Gizmos.color = Color.blue;
            Gizmos.DrawLine(Position, Position + withdrawal * 5);
            Gizmos.color = Color.black;
            Gizmos.DrawLine(Position, Position + independence * 5);
        }
Example #5
0
 /// <summary>
 /// Flock Cohesion
 /// </summary>
 private Vector3 CalculateCohesion(List <Boid> neighbours)
 {
     return((Vector3.Lerp(BoidUtility.GetAveragePosition(neighbours), Position, 0.5f) - Position).normalized);
 }