Ejemplo n.º 1
0
    public override Vector3 CalculateMove(planeBehavior plane, List <Transform> context, Flock flock)
    {
        if (weights.Length != behaviors.Length)
        {
            Debug.LogError("Array length mismatch in " + name, this);
            return(Vector3.zero);
        }
        Vector3 move = Vector3.zero;
        Vector3 partialMove;

        for (int i = 0; i < behaviors.Length; i++)
        {
            partialMove = behaviors[i].CalculateMove(plane, context, flock) * weights[i];
            if (partialMove != Vector3.zero)
            {
                if (partialMove.sqrMagnitude > weights[i] * weights[i])
                {
                    partialMove.Normalize();
                    partialMove *= weights[i];
                }
                move += partialMove;
            }
        }
        return(move);
    }
Ejemplo n.º 2
0
    public override Vector3 CalculateMove(planeBehavior plane, List <Transform> context, Flock flock)
    {
        Vector3 centerOffset = center - plane.transform.position;
        float   t            = centerOffset.magnitude / radius;

        if (t < 0.9f)
        {
            return(Vector3.zero);
        }
        return(centerOffset * t * t);
    }
Ejemplo n.º 3
0
    private List <Transform> getNearbyObject(planeBehavior agent)
    {
        List <Transform> context = new List <Transform>();

        Collider[] contextcolliders = Physics.OverlapSphere(agent.transform.position, NeighborRadius);
        foreach (var collider in contextcolliders)
        {
            if (collider != agent._Collider)
            {
                context.Add(collider.transform);
            }
        }
        return(context);
    }
Ejemplo n.º 4
0
    public override Vector3 CalculateMove(planeBehavior plane, List <Transform> context, Flock flock)
    {
        if (context.Count == 0)
        {
            return(Vector3.zero);
        }
        Vector3 AlignMove = plane.transform.forward;

        foreach (var transform in context)
        {
            AlignMove += transform.forward;
        }
        AlignMove /= context.Count;
        AlignMove  = Vector3.SmoothDamp(plane.transform.forward, AlignMove, ref currentVelocity, 0.3f);

        return(AlignMove);
    }
Ejemplo n.º 5
0
    public override Vector3 CalculateMove(planeBehavior plane, List <Transform> context, Flock flock)
    {
        if (context.Count == 0)
        {
            return(Vector3.zero);
        }
        Vector3 cohesionMove = Vector3.zero;

        foreach (var transform in context)
        {
            cohesionMove += transform.position;
        }
        cohesionMove /= context.Count;

        cohesionMove -= plane.transform.position;

        cohesionMove = Vector3.SmoothDamp(plane.transform.forward, cohesionMove, ref currentVelocity, agentSmoothTime);
        return(cohesionMove);
    }
Ejemplo n.º 6
0
    public override Vector3 CalculateMove(planeBehavior plane, List <Transform> context, Flock flock)
    {
        if (context.Count == 0)
        {
            return(Vector3.zero);
        }
        Vector3 AvoidMove = Vector3.zero;
        int     nAvoid    = 0;

        foreach (var transform in context)
        {
            if (Vector3.SqrMagnitude(transform.position - plane.transform.position) < flock.SquareAvoidanceRadius)
            {
                nAvoid++;
                AvoidMove += plane.transform.position - transform.position;
            }
        }
        if (nAvoid > 0)
        {
            AvoidMove /= nAvoid;
        }
        return(AvoidMove);
    }
Ejemplo n.º 7
0
 public void RemoveAgent(planeBehavior agent)
 {
     agents.Remove(agent);
 }
Ejemplo n.º 8
0
 public void AddAgent(planeBehavior agent)
 {
     agents.Add(agent);
 }
Ejemplo n.º 9
0
 public abstract Vector3 CalculateMove(planeBehavior plane, List <Transform> context, Flock flock);