HasFinished() public method

public HasFinished ( ) : bool
return bool
Esempio n. 1
0
    public void fd(float pas, bool smoothRotation = true, bool evitementDesAutresAgents = true)
    {
        if (walkEmitter != null && walkEmitter.HasFinished())
        {
            walkEmitter.Play();
        }

        float finalDirection = direction;

        if (evitementDesAutresAgents)
        {
            //Liste des vecteurs générés pour éviter/fuir les obstacles et leurs poids
            List <Vector2> evitements      = new List <Vector2>();
            List <float>   poidsEvitements = new List <float>();
            List <Vector2> repulsions      = new List <Vector2>();
            List <float>   poidsRepulsions = new List <float>();

            Vector2 vectorDirection = Utils.vectorFromAngle(direction, 1f);

            Animal            currentAnimal;
            List <MemoryBloc> memoryBlocs = new List <MemoryBloc>(GetComponent <Memory>().getMemoyBlocs());
            MemoryBloc        currentBloc;
            for (int i = 0; i < memoryBlocs.Count; ++i)
            {
                currentBloc   = memoryBlocs[i];
                currentAnimal = currentBloc.getEntity() as Animal;
                if (currentAnimal != null && !currentAnimal.estMort() && currentAnimal != agentToDontDodge)
                {
                    float   distance = Vector2.Distance(currentBloc.getLastPosition(), transform.position);
                    Vector2 vectorFaceToLastPosition = Utils.vectorFromAngle(getFaceToDirection(currentBloc.getLastPosition()));
                    float   angle = Vector2.Angle(vectorDirection, vectorFaceToLastPosition);

                    //Ajout d'un vecteur pour éviter et passer sur le côté de l'obstacle
                    if (angle <= 90 && distance < 1.5f)
                    {
                        //Calcul de la force ( priorité ) de l'évitement afin de pondérer les différents vecteur
                        float force = (distance <= 1) ? 1f : (1f - (distance - 1f) / 4f);

                        Vector2 vectorDirectionCurrentLoup = Utils.vectorFromAngle(currentAnimal.direction);
                        if (distance < .75f || Vector2.Angle(vectorDirection, vectorDirectionCurrentLoup) > 18)
                        {
                            Vector2        subVector   = vectorDirection - vectorDirectionCurrentLoup;
                            List <Vector2> orthogonaux = Utils.getOrthogonalsVectors(vectorFaceToLastPosition);
                            if (Vector2.Angle(orthogonaux[1], subVector) < Vector2.Angle(orthogonaux[0], subVector))
                            {
                                evitements.Add(orthogonaux[1]);
                            }
                            else
                            {
                                evitements.Add(orthogonaux[0]);
                            }

                            poidsEvitements.Add(force);
                        }

                        //Ajout d'un vecteur pour reculer par rapport à l'obstacle
                        if (force > .5f)
                        {
                            repulsions.Add(Utils.vectorFromAngle(getFaceToDirection(currentBloc.getLastPosition()) + 180));
                            poidsRepulsions.Add((force - .5f) / .5f);
                        }
                    }
                }
            }

            Vector2 sommeEvitements = new Vector2(0, 0);
            for (int i = 0; i < evitements.Count; ++i)
            {
                sommeEvitements += evitements[i] * poidsEvitements[i];
            }
            Vector2 sommeRepulsions = new Vector2(0, 0);
            for (int i = 0; i < repulsions.Count; ++i)
            {
                sommeRepulsions += repulsions[i] * poidsRepulsions[i];
            }

            //Affichage des vecteurs si un vectorDisplayer est assigné au script
            if (vectorDisplayer != null)
            {
                VectorDisplayer displayer = vectorDisplayer.GetComponent <VectorDisplayer>();
                displayer.transform.position = transform.position;
                displayer.setBluePosition(vectorDirection * 6);
                if (sommeEvitements != Vector2.zero)
                {
                    displayer.setRedPosition(sommeEvitements * 6);
                }
                else
                {
                    displayer.hideRedVector();
                }
                displayer.transform.Rotate(new Vector3(0, 0, 1), 90);
            }
            sommeEvitements.Normalize();
            sommeRepulsions.Normalize();
            finalDirection = Utils.angleFromVector(vectorDirection + .8f * sommeEvitements + sommeRepulsions);
        }

        float currentDirection = direction;

        if (smoothRotation)
        {
            //Limitation du degré de rotation à parcourir à chaque tick
            currentDirection = GetComponent <Rigidbody2D>().rotation;
            float   rotateValue            = 4;
            Vector2 vectorCurrentDirection = Utils.vectorFromAngle(currentDirection);
            Vector2 vectorFinalDirection   = Utils.vectorFromAngle(finalDirection);
            if (Vector2.Angle(vectorCurrentDirection, vectorFinalDirection) <= rotateValue)
            {
                currentDirection = finalDirection;
            }
            else
            {
                float determinant = vectorCurrentDirection.x * vectorFinalDirection.y - vectorCurrentDirection.y * vectorFinalDirection.x;
                if (determinant > 0)
                {
                    currentDirection += rotateValue;
                }
                else
                {
                    currentDirection -= rotateValue;
                }
            }
        }

        GetComponent <Rigidbody2D>().rotation = currentDirection;
        GetComponent <Rigidbody2D>().velocity = transform.up * pas;
    }
Esempio n. 2
0
    public bool IsPlaying(AudioChannel channel)
    {
        FMOD_StudioEventEmitter emitter = this.GetEmitter(channel);

        return(!emitter.HasFinished());
    }