Hello I have a question that seems simple but has stumped my because I am failing to wrap my mind around the math to calculate all the points between an x position and a y position.
So what I have created is a script to paint the terrain under an object. I am getting that area under the object by converting the positions of the objects corners to terrain coordinates.
My issue is I am unable to get the painted terrain area to fit closely to the objects corners. I just get a box around the object limited by the maximum x and max y coordinates.
How do I limit the area to just the corners? I know its a math issue. I just can’t figure it out.
Here is how I am currently checking coordinates.
if (x >= firstPoint.x && x <= thirdpoint.x && y <=fourthpoint.y)
{
if (y >= secondpoint.y && y <= fourthpoint.y )
{
float a0 = maps[x, y, 0];
float a1 = maps[x, y, 1];
a0 += Random.value * noiseScale;
a1 += Random.value * noiseScale;
float total = a0 + a1;
maps[x, y, 0] = a0 / total;
maps[x, y, 1] = a1 / total;
}
else
{
float a0 = maps[x, y, 0];
float a1 = maps[x, y, 1];
float total = a0 + a1;
maps[x, y, 0] = a0;
maps[x, y, 1] = a1;
}
}
The “points” are the spheres on the corners of the object.