- Home /
Aligning planes thin gap? c#
Im currently developing a 2d side scrolling game that uses planes to build up the scenery.
For example it will create 10 planes in a row, aligned next to eachother, each with the next texture on. But for some reason there is sometimes little thin lines between the planes!
This is frustrating, as they should be perfectly aligned. Im using the following function to get the position of the next plane
Vector3 GetNextPosition(GameObject rightPlane)
{
GameObject leftPlane = planes[planes.Count-1];
float xPos = leftPlane.transform.position.x + (leftPlane.transform.lossyScale.x*0.5f) + (rightPlane.transform.lossyScale.x*0.5f);
//this uses the lossyScale.z as the planes are rotated (90,180,0) so theyre upright, and the y scale becomes z
float yPos = leftPlane.transform.position.y - (leftPlane.transform.lossyScale.z*0.5f) + (rightPlane.transform.lossyScale.z*0.5f);
float zPos = leftPlane.transform.position.z;
return new Vector3(xPos + leftMargin, yPos, zPos);
}
The plane is imported from 3dStudioMax and is only 1 unit by 1 unit. I got the same result whilst using the standard unity 10x10 plane, but decided to make it 1x1 to keep hte tri and quad count down a bit.
Also there is a thin line of colours at the edge of my transparent png. I have read alot about this and tried a lot of things to get rid of this line, such as using exporting in GIMP with a new transparent layer behind the png, and unchecking the 'Save color values from transparent pixels' and 'Save background color'!
Any help would be greatly appreciated!
I'm using the perspective camera, if that makes ANY difference!
you should put the image on a transparent background but the background should be colored even though its transparent. It should be NEARLY identical in color to the actual object edge so that whatever pixels bleed through it still looks ok.
what you need to be googling for is
texture edge padding
that will give you some info on what is going on and how to correct it.
3dsmax-> render to texture ->padding
for example.
again though that padding needs to be the same color as the edge.
Whats happening is your graphics card is trying to take a high resolution image and display it at a lower resolution.
it does this by taking a pixel and its nearby neighbors and averaging color values to create a new pixel which roughly represents those several.
near the edge of your texture the neighbors are those "transparent" pixels. But they still count for the purposes of being sampled.
The large difference in color means near the edge its trying to make one pixel out of say pure white and pure red.
That doesn't work out well, you get a stream of different colors because averaging the neighbors means sometimes your averaging more colors together producing a new color each time.
that is why you want the edge to be the same color GOING PAST the edge.
hope this helps. :
Thank you for your detailed response. I have tried many things, from many answers on this site regarding the 'texture edge padding' though i didnt know the jargon, so it's easier to search for it now! thanks! I have tried a lot of photoshop batches, that use the gassian blur merging and whatever to create the padding, and then uses the alpha channel to but it just end up with the thin lines still appearing and now a border round each image of about 10 pixels black. or just a totally black background, following this tutorial of unitys site too! I get the same effect http://docs.unity3d.com/Documentation/$$anonymous$$anual/HOWTO-alphamaps.html
Is there a certain blend mode i need to choose for that?
Your answer
Follow this Question
Related Questions
Trying to make a texture fill an entire Plane 0 Answers
2d PNG on Plane Texture padding 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to make a ball jump? 2 Answers