public void GetSteeringBehaviorVector(out Vector3 steer, SteeringAgent mine, Vector3 worldDimensions, float containmentBuffer)
        {
            bufferedPosition = mine.Position + mine.Velocity * lookAheadSeconds;
            float distanceToBorder = float.MaxValue;

            if (worldDimensions.x > 0)
            {
                minArray[0]        = distanceToBorder;
                minArray[1]        = mine.Position.x;
                minArray[2]        = worldDimensions.x - mine.Position.x;
                distanceToBorder   = Mathf.Min(minArray);
                bufferedPosition.x = Mathf.Clamp(bufferedPosition.x, containmentBuffer, worldDimensions.x - containmentBuffer);
            }
            else
            {
                bufferedPosition.x = 0;
            }
            if (worldDimensions.y > 0)
            {
                minArray[0]        = distanceToBorder;
                minArray[1]        = mine.Position.y;
                minArray[2]        = worldDimensions.y - mine.Position.y;
                distanceToBorder   = Mathf.Min(minArray);
                bufferedPosition.y = Mathf.Clamp(bufferedPosition.y, containmentBuffer, worldDimensions.y - containmentBuffer);
            }
            else
            {
                bufferedPosition.y = 0;
            }
            if (worldDimensions.z > 0)
            {
                minArray[0]        = distanceToBorder;
                minArray[1]        = mine.Position.z;
                minArray[2]        = worldDimensions.z - mine.Position.z;
                distanceToBorder   = Mathf.Min(minArray);
                bufferedPosition.z = Mathf.Clamp(bufferedPosition.z, containmentBuffer, worldDimensions.z - containmentBuffer);
            }
            else
            {
                bufferedPosition.z = 0;
            }
            if (bufferedPosition == mine.Position + mine.Velocity)
            {
                steer = Vector3.zero;
                return;
            }
            if (distanceToBorder <= 0)
            {
                distanceToBorder = .001f;
            }

            mine.GetSeekVector(out steer, bufferedPosition);
            steer *= containmentBuffer / distanceToBorder;
        }
Beispiel #2
0
        public override void GetSteeringBehaviorVector(out Vector3 steer, SteeringAgent mine, SurroundingsContainer surroundings)
        {
            if (!mine.HasAgentProperty(targetIDAttributeName))
            {
                mine.SetAgentProperty(targetIDAttributeName, -1);
            }
            int chosenTargetID = mine.GetAgentProperty <int>(targetIDAttributeName);

            HashSet <Agent> allTargets = GetFilteredAgents(surroundings, this);

            if (allTargets.Count == 0)
            {
                if (HasPursuitTarget(mine))
                {
                    DisengagePursuit(mine, chosenTargetID);
                }
                steer = Vector3.zero;
                return;
            }

            Agent closestTarget = ClosestPursuableTarget(allTargets, mine);

            if (!closestTarget || !closestTarget.CanBeCaughtBy(mine))
            {
                if (HasPursuitTarget(mine))
                {
                    DisengagePursuit(mine, chosenTargetID);
                }
                steer = Vector3.zero;
                return;
            }

            if (closestTarget.agentID != chosenTargetID)
            {
                DisengagePursuit(mine, chosenTargetID);
                EngagePursuit(mine, closestTarget);
            }

            Vector3 distance                   = closestTarget.Position - mine.Position;
            float   est_timeToIntercept        = distance.magnitude / mine.activeSettings.maxSpeed;
            Vector3 predictedInterceptPosition = closestTarget.Position + closestTarget.Velocity * est_timeToIntercept;

            AttemptCatch(mine, closestTarget);

            mine.GetSeekVector(out steer, predictedInterceptPosition);
        }
Beispiel #3
0
        public override void GetSteeringBehaviorVector(out Vector3 steer, SteeringAgent mine, SurroundingsContainer surroundings)
        {
            //steer used as midpoint to prevent garbage
            steer = Vector3.zero;
            float count = 0;

            foreach (Agent other in GetFilteredAgents(surroundings, this))
            {
                if (WithinEffectiveRadius(mine, other))
                {
                    steer += (other.Position);
                    count++;
                }
            }
            if (count > 0)
            {
                steer /= (count);
                mine.GetSeekVector(out steer, steer);
            }
            else
            {
                steer = Vector3.zero;
            }
        }