protected override Vector2?CalculateForceComponentsInternal()
        {
            activation = 0.0f;

            var visibleAgentsCount = m_sensor.touchingObjects.Count;
            var meanPosition       = Vector2.zero;

            foreach (var collider in m_sensor.touchingObjects)
            {
                var agent = collider.GetComponent <ParentAgent>()?.agent;
                if (agent == null)
                {
                    continue;
                }
                meanPosition += agent.position;
            }

            if (visibleAgentsCount <= 0)
            {
                return(null);
            }

            meanPosition /= visibleAgentsCount;

            activation = 1.0f;
            return(SteeringBehaviourUtils.Seek(meanPosition, 0.5f, 0.01f, this));
        }
Exemplo n.º 2
0
        protected override Vector2?CalculateForceComponentsInternal()
        {
            if (m_path.pointsCount <= 0)
            {
                return(null);
            }

            activation = 1.0f;
            var isLast            = m_pointIndex == m_path.pointsCount - 1;
            var canIncrementIndex = m_loop || !isLast;

            var target = m_path.GetPoint(m_pointIndex);

            if (canIncrementIndex && Vector2.Distance(target, position) < m_pointRadius)
            {
                m_pointIndex = (m_pointIndex + 1) % m_path.pointsCount;
            }

            var brakingRadius = 0.0f;
            var epsilonRadius = 0.0f;

            if (m_shouldSlowNearLastPoint && isLast)
            {
                brakingRadius = m_brakingRadius;
                epsilonRadius = m_epsilonRadius;
            }

            return(SteeringBehaviourUtils.Seek(target, brakingRadius, epsilonRadius, this));
        }
        protected override Vector2?CalculateForceComponentsInternal()
        {
            if (m_threat == null)
            {
                return(null);
            }

            activation = 1.0f;
            return(SteeringBehaviourUtils.Flee(m_threat.position, this));
        }
        protected override Vector2?CalculateForceComponentsInternal()
        {
            if (m_target == null)
            {
                return(null);
            }

            activation = 1.0f;
            var brakingRadius = m_slowNearTarget ? m_brakingRadius : 0.0f;
            var epsilonRadius = m_slowNearTarget ? m_epsilonRadius : 0.0f;

            return(SteeringBehaviourUtils.Seek(m_target.position, brakingRadius, epsilonRadius, this));
        }
        protected override Vector2?CalculateForceComponentsInternal()
        {
            activation = 0.0f;

            if (m_sensor == null)
            {
                return(null);
            }

            var visibleObstaclesCount = m_sensor.touchingObjects.Count;

            var meanPos = Vector2.zero;

            foreach (var obstacle in m_sensor.touchingObjects)
            {
                meanPos += (Vector2)obstacle.transform.position;
            }

            activation = visibleObstaclesCount > 0 ? 1.0f : 0.0f;
            var force = visibleObstaclesCount > 0 ? SteeringBehaviourUtils.Flee(meanPos, this) : Vector2.zero;

            return(force);
        }
Exemplo n.º 6
0
 protected override Vector2?CalculateForceComponentsInternal()
 {
     activation = 1.0f;
     return(SteeringBehaviourUtils.Seek(m_targetPosition, 0.0f, 0.0f, this));
 }