Exemplo n.º 1
0
        public override Vector2 CalculateMove(FlockAgent agent, List <Transform> context, Flock flock)
        {
            Vector2 centerOffset = center - (Vector2)agent.transform.position;
            float   t            = centerOffset.magnitude / radius;

            // If the agent is within the pull radius, then don't need to influence
            if (t < pullRadius)
            {
                return(Vector2.zero);
            }

            return(centerOffset * t * t);
        }
Exemplo n.º 2
0
        public override Vector2 CalculateMove(FlockAgent agent, List <Transform> context, Flock flock)
        {
            // If no neighbors, then nothing to move towards
            if (context.Count == 0)
            {
                return(Vector2.zero);
            }

            // Add all points together and average
            Vector2          move            = Vector2.zero;
            List <Transform> filteredContext = (filter == null) ? context : filter.Filter(agent, context);

            foreach (Transform item in filteredContext)
            {
                move += (Vector2)item.position;
            }

            move /= context.Count;

            // Create offset from agent's current position
            move -= (Vector2)agent.transform.position;
            move  = Vector2.SmoothDamp(agent.transform.up, move, ref currentVelocity, agentSmoothTime);
            return(move);
        }
Exemplo n.º 3
0
 public void ChangeFlock(Flock newFlock)
 {
     Initialize(newFlock, id);
     transform.parent = newFlock.transform;
 }
Exemplo n.º 4
0
 public abstract Vector2 CalculateMove(FlockAgent agent, List <Transform> context, Flock flock);
Exemplo n.º 5
0
        public override Vector2 CalculateMove(FlockAgent agent, List <Transform> context, Flock flock)
        {
            // If no neighbors, nothing to steal
            if (context.Count == 0)
            {
                return(Vector2.zero);
            }

            // Instead of moving, steal!
            List <Transform> filteredContext = (filter == null) ? context : filter.Filter(agent, context);

            foreach (Transform neighbor in filteredContext)
            {
                FlockAgent neighborAgent = neighbor.GetComponent <FlockAgent>();
                if (neighborAgent != null && Random.Range(0f, 1f) < stealChance)
                {
                    flock.StealAgentFromFlock(neighborAgent, neighborAgent.AgentFlock);
                }
            }

            return(Vector2.zero); // nothing to move
        }
Exemplo n.º 6
0
        public override Vector2 CalculateMove(FlockAgent agent, List <Transform> context, Flock flock)
        {
            // If no neighbors, maintain current alignment
            if (context.Count == 0)
            {
                return(agent.transform.up);
            }

            // Add all alignments of neighbors and average
            Vector2          move            = Vector2.zero;
            List <Transform> filteredContext = (filter == null) ? context : filter.Filter(agent, context);

            foreach (Transform neighbor in filteredContext)
            {
                move += (Vector2)neighbor.transform.up;
            }

            return(move / context.Count); // average
        }
Exemplo n.º 7
0
        public override Vector2 CalculateMove(FlockAgent agent, List <Transform> context, Flock flock)
        {
            // Not even enough transforms in the area to form an enemy
            // If agent already stolen, then don't continue
            if (context.Count < neighborAmount) // || flock.IsAgentStolen(agent))
            {
                return(Vector2.zero);
            }

            List <Transform> filteredContext = (filter == null) ? context : filter.Filter(agent, context);

            if (filteredContext.Count >= neighborAmount)
            {
                EnemyBase enemyBase  = Instantiate(flockPrefab, agent.transform.position, Quaternion.identity);
                Flock     enemyFlock = enemyBase.Flock;
                // Try adding enemies in here. Other option is adding in the instantiation of the flock
                // Capture agents when formed?
                foreach (Transform neighbor in filteredContext)
                {
                    FlockAgent neighborAgent = neighbor.GetComponent <FlockAgent>();
                    if (neighborAgent != null)
                    {
                        enemyFlock.StealAgentFromFlock(neighborAgent, neighborAgent.AgentFlock);
                    }
                }

                enemyFlock.StealAgentFromFlock(agent, agent.AgentFlock);
            }


            return(Vector2.zero);
        }