tirsdag den 1. november 2016

Heatmap


To give the player a visualisation of where the largest amount of resources are located, we've created a heatmap. This will help the player choose the optimal location for the extractor building. 

The heatmap script uses an array of vectors together with an intensity and radius variable for each point to calculate each point's contribution to the heat map.
Using a gradient texture the script will select a level of gradient depending on the variables for that point
In the code snippet below the arrays are created with the length of count, which is the amount of points. Then the script cycles through the points using a for loop. Each point is assigned a random position, radius and intensity.

        positions = new Vector2[count];
        radiuses = new float[count];
        intensities= new float[count];

        for (int i = 0; i < positions.Length; i++)
        {
            positions[i] = new Vector2(Random.Range(-scaleX, scaleX), Random.Range(-scaleY, scaleY));
            radiuses[i] = Random.Range(radiusRangeMin, radiusRangeMax);
            intensities[i] = Random.Range(intensityMin, intensityMax);
        }

After the points have been calculated they're sent to the shader using SetVectorArray and SetFloatArray.

material.SetInt("_Points_Length", positions.Length);
        material.SetVectorArray("_Points", positions.Select(v => (Vector4)v).ToArray());
        material.SetFloatArray("_Radius", radiuses);
        material.SetFloatArray("_intensity", intensities);

The GetIntensity method takes a vector2 position and returns the intensity of resources in that loaction by taking the intensity of all the points near the vector2 position.
This is the intensity that will decide the amount of resources that can be harvested from an extractor placed in that position.

    public float GetIntensity(Vector2 pos)
    {
        float intensity = 0;
        for (int i = 0; i < positions.Length; i++)
        {
            if (Vector2.Distance(pos, positions[i]) < radiuses[i])
                intensity += intensities[i];
        }
        return intensity;
    }

Related Posts:

  • Our very own truckHours of work later and we've finally got a truck to transport supplies from A to B. Based off of the american truck design, this truck is one of the key art assets for the visual presentation of our game's system. Theref… Read More
  • Get ready to rumble!Seriously, get ready because these bad boys are gonna rock your world. Here is the last three Exstractor sprites that were made for Corporate Quest. They were of course made using the same vector style graphics that were ment… Read More
  • Work on the extractors has finishedFinally finished the last few buildings for resource harvesting, here they are! Each building represents the harvesting method of a basic resource, like crops, ores and oil. Currently the only building for resource gat… Read More
  • Work in progress...The newest addition to Corporate Quest's list of buildings, the Building Site. The building site is used in-game as a visual representation of a non specialized building, whether it be a resource extractor or a factory.… Read More
  • Moodboards/ ArtstyleLet's set the mood To set up the style for the game we chose to research and develop a color style to capture the player's attention, and an art style for the in-game assets to specify the look of the game. Choosing a colo… Read More

0 kommentarer:

Send en kommentar