Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        if (isLeader)
        {
            //Me muevo independientemente. Con avoidance.
            LeaderDir = (Objective.transform.position - transform.position).normalized;

            if (Vector3.Distance(transform.position, Obstacle.transform.position) < AvoidanceRadius)
            {
                Avoid      = Avoidance.getAvoidance(transform.position, Obstacle.transform.position);
                LeaderDir += Avoid;
            }

            LeaderDir.y = 0;

            transform.forward = Vector3.Slerp(transform.forward, LeaderDir, RotationSpeed * Time.deltaTime);

            transform.position += transform.forward * Velocity * Time.deltaTime;
        }
        else
        {
            List <Vector3> AllyPos = new List <Vector3>();
            foreach (var Ally in Allies)
            {
                AllyPos.Add(Ally.transform.position);
            }

            if (Vector3.Distance(transform.position, Obstacle.transform.position) < AvoidanceRadius)
            {
                Avoid    = Avoidance.getAvoidance(transform.position, Obstacle.transform.position);
                DirToGo += Avoid;
            }

            Le = (Leader.transform.position - transform.position).normalized;
//            Vector3 avoid = Avoidance.getAvoidance(transform.position,);
            Al = Floq.getAlignment(transform.position, AllyPos);
            Co = Floq.getCohesion(transform.position, AllyPos) * cohetionWeight;
            Se = Floq.getSeparation(transform.position, AllyPos, RadioDeFloq) * separationWeight;

            DirToGo = Avoid + Le + Al + Co + Se;

            DirToGo.y = 0;

            transform.forward = Vector3.Slerp(transform.forward, DirToGo, RotationSpeed * Time.deltaTime);

            transform.position += transform.forward * Velocity * Time.deltaTime;
        }
    }
Esempio n. 2
0
 // Update is called once per frame
 void Update()
 {
     avoidance = Avoidance.getAvoidance(transform.position, Obstacle.transform.position);
 }