コード例 #1
0
ファイル: Sensor.cs プロジェクト: TheCanadians/BachelorGit
    private void FixedUpdate()
    {
        // Vector between EndPoint and Sensor
        Vector2 sensorDirection = EndPoint.transform.position - this.transform.position;

        sensorDirection.Normalize();

        // Raycast to check for wall hit
        RaycastHit2D wallHit = Physics2D.Raycast(this.transform.position, sensorDirection, MAX_DISTANCE, SensorLayer);

        // Check what was hit
        if (wallHit.collider == null)
        {
            wallHit.distance = MAX_DISTANCE;
        }

        distance = wallHit.distance;
        // Add noise between min and max Noise to distance to simulate reality better
        //float noise = Random.Range(pM.minNoise, pM.maxNoise);
        float noise = RandomFromDistribution.RandomNormalDistribution(0, pM.stdDev);

        distance += noise;
        // Set EndPoint position to raycast hit position
        EndPoint.transform.position = (Vector2)this.transform.position + sensorDirection * wallHit.distance;
    }
コード例 #2
0
    /// <summary>
    /// Mutate the connection weights
    /// </summary>
    public void MutateConnectionWeight()
    {
        foreach (ConnectionGene connection in _connections.Values)
        {
            if (Random.Range(0f, 1f) <= _PROBABILITY_PERTURBING)
            {
                //Pertube weight
                double weight = connection.Weight;
                //weight += Random.Range(0f, 1f) * 2 * 0.2 - 0.2;

                float debugValue = RandomFromDistribution.RandomNormalDistribution(0, _SIGMA_GAUSS);
                //float debugValue = Random.Range(0f, 1f) - Random.Range(0f, 1f);
                //float debugValue = Random.Range(-_SIGMA_GAUSS, _SIGMA_GAUSS);
                //Debug.Log(debugValue);

                weight += debugValue;

                connection.Weight = weight;
            }
            else
            {
                //Assign new weight
                connection.Weight = Random.Range(-2.0f, 2.0f);
            }
        }
    }
コード例 #3
0
    // Update is called once per frame
    void Update()
    {
        data nData      = new data();
        int  newValue   = Mathf.RoundToInt(RandomFromDistribution.RandomNormalDistribution(1000.0f, 1.0f));
        bool valueFound = false;

        foreach (data cData in ValueList)
        {
            if (cData.value == newValue)
            {
                nData      = cData;
                valueFound = true;
            }
        }

        if (valueFound)
        {
            ValueList.Remove(nData);
            nData.score += 1;
            ValueList.Add(nData);
        }
        else
        {
            nData.value = newValue;
            nData.score = 1;
            ValueList.Add(nData);
        }

        foreach (data cData in ValueList)
        {
            GameObject nGO = GameObject.Instantiate(CubePrefab);
            nGO.transform.position = new Vector3(cData.value * 3.0f, cData.score * 1, 0.0f);
        }
    }
コード例 #4
0
    void Distribute()
    {
        Vector3 normalPosition = new Vector3(0.0f, 0.0f, 0.0f);

        normalPosition.x = transform.position.x + RandomFromDistribution.RandomNormalDistribution(0.0f, 1.0f);
        normalPosition.y = transform.position.y + RandomFromDistribution.RandomNormalDistribution(0.0f, 1.0f);

        Instantiate(clone, normalPosition, transform.rotation);
    }
コード例 #5
0
ファイル: AsteroidBelt.cs プロジェクト: erdostamasa/ADEN
    private Vector2 RandomCirclePosition()
    {
        //calculate random offset form orbit
        //float offset = Random.Range(-orbitOffset, orbitOffset);
        float offset      = RandomFromDistribution.RandomNormalDistribution(0, orbitOffset);
        float orbit       = rotationRadius + offset;
        float randomAngle = Random.Range(0f, 360f);

        float posX = center.position.x + Mathf.Cos(randomAngle * Mathf.Deg2Rad) * orbit;
        float posY = center.position.y + Mathf.Sin(randomAngle * Mathf.Deg2Rad) * orbit;

        return(new Vector2(posX, posY));
    }
コード例 #6
0
    void Awake()
    {
        clouds = new SpriteRenderer[numberOfClouds];
        speeds = new float[numberOfClouds];

        int     cloudMaxIndex = cloudSprites.Length - 1;
        int     index;
        Vector3 position;

        for (int i = 0; i < numberOfClouds; i++)
        {
            index     = Random.Range(0, cloudMaxIndex);
            position  = new Vector3(Random.Range(-1.0f * xLimit, xLimit), RandomFromDistribution.RandomNormalDistribution(yLimit, yLimit / spread), 0.0f);
            clouds[i] = Instantiate(cloudSprites[index], position, Quaternion.identity);
            speeds[i] = Random.Range(-10.0f, 10.0f);
        }
    }
コード例 #7
0
ファイル: Roads.cs プロジェクト: Alan-Baylis/ProceduralCity-1
    //connect the points to form roads, and store the neighbours
    List <Vector3> returnNeighbours(Vector3 point)
    {
        //returns neighours of the given point
        List <Vector3> neighbours = new List <Vector3> ();

        for (int i = 0; i < vertices.Count; i++)
        {
            float distance = (point - vertices[i]).magnitude;
            mean    = 6f;
            std_dev = 2f;
            //generate a number from the random distribution with mean and std deviation and use that as a metric to decide
            float radius = RandomFromDistribution.RandomNormalDistribution(mean, std_dev);

            Console.WriteLine(distance);
            if (distance < radius)
            {
                neighbours.Add(vertices[i]);
            }
        }
        return(neighbours);
    }
コード例 #8
0
ファイル: AsteroidBelt.cs プロジェクト: erdostamasa/ADEN
    private void SpawnAsteroids()
    {
        deleted = 0;
        int spawned = 0;

        errorCounter = 0;
        while (errorCounter < 10000 && spawned <= numOfAsteroids)
        {
            //Choose a random asteroid from list
            GameObject rndAsteroid = asteroids[Random.Range((int)0, (int)asteroids.Count)];

            Vector2    pos         = RandomCirclePosition();
            GameObject newAsteroid = Instantiate(rndAsteroid, pos, Quaternion.identity);
            float      scale       = RandomFromDistribution.RandomNormalDistribution(averageScale, stdDeviation);
            if (scale < minScale)
            {
                scale = minScale;
            }
            if (scale > maxScale)
            {
                scale = maxScale;
            }
            newAsteroid.transform.localScale = new Vector3(scale, scale, 1);
            Collider2D[] contacts = new Collider2D[1];
            if (Physics2D.OverlapBoxAll(pos, newAsteroid.transform.localScale * 5f, 0).Length > 1)
            {
                DestroyImmediate(newAsteroid);
                deleted++;
            }
            else
            {
                newAsteroid.transform.parent   = transform;
                newAsteroid.transform.rotation = quaternion.Euler(0, 0, Random.Range(0f, 360f));
                spawned++;
            }

            errorCounter++;
        }
    }
コード例 #9
0
    // Update is called once per frame
    void FixedUpdate()
    {
        float shootRandomDirection = RandomFromDistribution.RandomNormalDistribution(0, 0.5f);

        Player[]      players          = GameObject.FindObjectsOfType <Player>();
        List <Player> playersWithoutMe = new List <Player>();
        Player        me        = null;
        int           currentId = gameObject.GetInstanceID();

        for (int i = 0; i < players.Length; i++)
        {
            if (players[i].gameObject.GetInstanceID() != currentId)
            {
                playersWithoutMe.Add(players[i]);
            }
            else
            {
                me = players[i];
            }
        }
        Player nearestPlayer     = null;
        float  nearestPlayerDist = 10000;

        if (me != null)
        {
            for (int i = 0; i < playersWithoutMe.Count; i++)
            {
                float dist = Vector3.Distance(playersWithoutMe[i].gameObject.transform.position,
                                              me.gameObject.transform.position);
                if (dist < nearestPlayerDist)
                {
                    nearestPlayerDist = dist;
                    nearestPlayer     = playersWithoutMe[i];
                }
            }
        }
        if (nearestPlayer != null)
        {
            Player.Shoot(new Vector3(nearestPlayer.transform.position.x + shootRandomDirection,
                                     nearestPlayer.transform.position.y + shootRandomDirection, 0));
        }

        Vector3Int bufPos;

        if ((currentWaypoint.x != 0 && currentWaypoint.y != 0) &&
            (Math.Abs(currentWaypoint.x - transform.position.x) > 1.1 ||
             Math.Abs(currentWaypoint.y - transform.position.y) > 1.1))
        {
            bufPos = gridLayout.WorldToCell(new Vector3(transform.position.x, transform.position.y, 0));
            Vector2 direction = gridLayout.CellToWorld(new Vector3Int(currentWaypoint.x, currentWaypoint.y, 0));
            direction = direction - new Vector2(bufPos.x, bufPos.y);
            direction = direction.normalized;
            Player.Move(direction);
            return;
        }
        bufPos = gridLayout.WorldToCell(new Vector3(transform.position.x, transform.position.y, 0));
        Vector2Int from = new Vector2Int(bufPos.x, bufPos.y);

        FieldTile[,] map = gameManager._field.getArray();
        currentWaypoint  = ChooseWayPoint(map, from);
        Debug.Log(currentWaypoint);
        Vector2Int[] path = FloodFill.GetPath(map, from, currentWaypoint, 3);
        if (path != null)
        {
            if (path.GetLength(0) > 1)
            {
                currentWaypoint = path[1];
            }
            else
            {
                if (path.GetLength(0) > 0)
                {
                    currentWaypoint = path[0];
                }
                else
                {
                    return;
                }
            }
            Vector2 direction = gridLayout.CellToWorld(new Vector3Int(currentWaypoint.x, currentWaypoint.y, 0));
            direction = direction - new Vector2(bufPos.x, bufPos.y);
            direction = direction.normalized;
            Player.Move(direction * Velocity);
        }
    }
コード例 #10
0
ファイル: NormalDistribution.cs プロジェクト: Tonatew/Pesca-
 public float GetRandomFloat()
 {
     return(RandomFromDistribution.RandomNormalDistribution(mean, standardDeviation));
 }