Esempio n. 1
0
    public override Vector2 CalculateMove(FlockAgent agent, List <Transform> context, Flock2 flock)
    {
        ///if no nab no adjust
        if (context.Count == 0)
        {
            return(Vector2.zero);
        }

        //add points and avrage
        Vector2 avoidanceMove = Vector2.zero;
        int     nAvoid        = 0;

        foreach (Transform item in context)
        {
            if (Vector2.SqrMagnitude(item.position - agent.transform.position) < flock.SquareAvoidanceRadius)
            {
                nAvoid++;
                avoidanceMove += (Vector2)(agent.transform.position - item.position);
            }
        }
        if (nAvoid > 0)
        {
            avoidanceMove /= nAvoid;
        }

        return(avoidanceMove);
    }
Esempio n. 2
0
    public override Vector2 CalculateMove(FlockAgent agent, List <Transform> context, Flock2 flock)
    {
        Vector2 centerOffset = center - (Vector2)agent.transform.position;
        float   t            = centerOffset.magnitude / radius;

        if (t < 0.9)
        {
            return(Vector2.zero);
        }
        return(centerOffset * t * t);
    }
Esempio n. 3
0
    public override Vector2 CalculateMove(FlockAgent agent, List <Transform> context, Flock2 flock)
    {
        // if no neighobers, stay the current course
        if (context.Count == 0)
        {
            return(agent.transform.up);
        }

        // add all the points and average it
        Vector2 AlignmentMove = Vector2.zero;

        foreach (Transform item in context)
        {
            AlignmentMove += (Vector2)item.transform.up;
        }
        AlignmentMove /= context.Count;

        return(AlignmentMove);
    }
Esempio n. 4
0
    public override Vector2 CalculateMove(FlockAgent agent, List <Transform> context, Flock2 flock)
    {
        if (context.Count == 0)
        {
            return(Vector2.zero);
        }

        //add points and avrage
        Vector2 cohesionMove = Vector2.zero;

        foreach (Transform item in context)
        {
            cohesionMove += (Vector2)item.position;
        }
        cohesionMove /= context.Count;

        //offse from agent pos

        cohesionMove -= (Vector2)agent.transform.position;
        cohesionMove  = Vector2.SmoothDamp(agent.transform.up, cohesionMove, ref currentVelocity, agentSmoothTime);
        return(cohesionMove);
    }
Esempio n. 5
0
    public override Vector2 CalculateMove(FlockAgent agent, List <Transform> context, Flock2 flock)
    {
        /// if data is not the same show where and dont move
        if (weights.Length != behaviours.Length)
        {
            Debug.Log("data miss match " + name, this);
            return(Vector2.zero);
        }
        //set move

        Vector2 move = Vector2.zero;

        //iterate through the behaviours
        for (int i = 0; i < behaviours.Length; i++)
        {
            Vector2 partialMove = behaviours[i].CalculateMove(agent, context, flock) * weights[i];

            if (partialMove != Vector2.zero)
            {
                if (partialMove.sqrMagnitude > weights[i] * weights[i])
                {
                    partialMove.Normalize();
                    partialMove *= weights[i];
                }
                move += partialMove;
            }
        }

        return(move);
    }
Esempio n. 6
0
 public abstract Vector2 CalculateMove(FlockAgent agent, List <Transform> context, Flock2 flock);
 public void AssignFlock(Flock2 flock)
 {
     assignedFlock = flock;
 }