Пример #1
0
 void Awake()
 {
     _pheromoneConfiguration = GetComponent <GlobalPheromoneConfiguration> ();
     _type = PheromoneTypes.None;
     _canReleasePheromone = false;
     _placementTimer      = 0.0f;
 }
Пример #2
0
    Vector3 FindMovmementDirection(PheromoneTypes pheromoneType)
    {
        Pheromone pheromone = _closestPheromone;

        Vector3 movementVector = new Vector3();

        Vector3 position = transform.position;

        // check that pheromone still exists
        if (!pheromone)
        {
            return(Vector3.zero);
        }

        Vector3 pheromonePosition = pheromone.transform.position;

        Vector3 pheromoneVector = (pheromonePosition - position).normalized;
        // find angle of pheromone
        float pheromoneAngle = Vector3.Dot(transform.forward, pheromoneVector);

        if (pheromoneAngle > _currentSmellAngle)
        {
            // weight added to concentration
            movementVector += pheromoneVector * pheromone.currentConcentration;
        }

        if (pheromoneType == PheromoneTypes.Fear || pheromoneType == PheromoneTypes.Pain)
        {
            return(-movementVector);
        }

        return(movementVector);
    }
Пример #3
0
    public void Initialize(PheromoneTypes type, float intensity, float diameter, float diffusionRate, float minimumConcentration, Color color)
    {
        this.type             = type;
        startIntensity        = intensity;
        _diffusionRate        = diffusionRate;
        _minimumConcentration = minimumConcentration;
        diffusionSphere.transform.localScale = new Vector3(diameter, diameter, diameter);

        // max radius = (n / (3/4 * PI * c))^(1/3)
        float maxRadius = Mathf.Pow(startIntensity / (0.75f * Mathf.PI * _minimumConcentration), 1f / 3f);
        float ttl       = maxRadius / _diffusionRate;

        // Initialize particle system
        var main = particleSystem.main;

        main.startLifetime = ttl;        //Mathf.Pow ((0.75f * _startIntensity) / (_minimumConcentration * Mathf.PI), 1f / 3f) / diffusionRate + 3.0f;
        main.startSpeed    = diffusionRate * 0.5f;
        main.startColor    = color;

        ParticleSystem.EmissionModule emission = particleSystem.emission;
        emission.rate = new ParticleSystem.MinMaxCurve(0f);

        ParticleSystem.ShapeModule shape = particleSystem.shape;
        shape.radius = diameter * 0.5f;

        particleSystem.Emit((int)(50.0f * startIntensity));

        _currentVisibility = true;

        calculateCurrentConcentration();
    }
Пример #4
0
    // Update is called once per frame
    // updates movement based on pheromones
    void Update()
    {
        _currentSmellAngle = Mathf.Cos(_boidConfiguration.smellAngle);
        // vector for pheromones set depending on nearest
        PheromoneTypes type = PheromoneTypes.None;
        Vector3        movementDirection = Vector3.zero;

        // check if pheromone still exists
        if (!_closestPheromone)
        {
            return;
        }
        else
        {
            type = _closestPheromone.type;
        }

        switch (type)
        {
        case PheromoneTypes.Food:
            // returns attraction vector
            movementDirection = FindMovmementDirection(type);
            canAttractBoid    = true;
            break;

        case PheromoneTypes.Fear:
            // returns repellent vector
            movementDirection = FindMovmementDirection(type);
            canAttractBoid    = false;
            break;

        default:

            break;
        }

        // if movement direction changes
        if (movementDirection.sqrMagnitude > 0.0f)
        {
            // set direction of the boid weight depends on movement sign
            if (canAttractBoid)
            {
                boid.toPheromone = movementDirection * .05f;
            }
            else if (!canAttractBoid)
            {
                boid.toPheromone = movementDirection * .99f;
            }
        }
    }
Пример #5
0
    // call to place specific type of pheromone
    public void PlacePheromone(Vector3 position, PheromoneTypes type)
    {
        PheromoneConfiguration pheromoneConfiguration = _pheromoneConfiguration.configs[type];

        float initialIntensity     = pheromoneConfiguration.initialIntensity;
        float initialScale         = pheromoneConfiguration.initialRadius;
        float diffusionRate        = pheromoneConfiguration.diffusionRate;
        float minimumConcentration = pheromoneConfiguration.minimumConcentration;
        Color color = pheromoneConfiguration.color;
        // instantiates the pheromone prefab in position
        GameObject newPheromone = Instantiate(pheromonePrefab, position, new Quaternion()) as GameObject;

        // initialize and visualizes new pheromone gameobject through pheromone script
        newPheromone.GetComponent <Pheromone>().Initialize(type, initialIntensity, initialScale, diffusionRate, minimumConcentration, color);
    }
Пример #6
0
 public void SetPheromoneType(PheromoneTypes type)
 {
     _type = type;
 }