I want to make an rts in either 2d or 3d (the graphics will look 2d, I’m just not sure which mode is best yet) and I currently have a noise map generator set to look like a pixelated rts map. Problem is I need a way to detect where the mouantains are and oceans are so that I can set certain properties for the units at these locations, such as preventing them to go there or slowing them down etc.
Since the map is procedural, I can’t manually do this. I need a way to generate the hitboxes assigned to certain colors, or “regions” since that is what I’m using to color the different parts of the noisemap.
Any help would be GREATLY appreciated as this is the only thing I’m not sure I will be able to do, and I’m pretty passionate about this little project. If you need anything else clarified, don’t hesitate to ask! Thanks!
You would typically use an array to represent the world map, and look up the appropriate array entry for the world position. (Using 1 array position = 1 world unit makes the math trivial, but other values only makes it slightly less trivial.)
This looks good, but if it is possible to detect the pixel you click on, how would one go about scanning a 2d plane for those pixels and then generating a hitbox for them?
I tend to use GetPixel for this. The process runs something like this.
Convert the mouse click from screen space → world space → texture space
Use GetPixel to grab the colour
However I will often go a different route. Since I tend to need all of the data from the texture anyway, for pathfinding and the like, I’ll load the whole thing into an array.
If I’m doing procedural generation it’s even easier. There is no need to check the texture, because I just made it. I can use the procedural generation data directly.