- Home /
Creating a smooth flat circle?
Hey there. I'm new to the Unity scene, but I've been programming for a while. I'm trying to create a simple test where you can click a 2D Circle. Super simple. However, when I try to make a flat circle to click, I run in to problems. I didn't want to use image sprites, so I initially used a flat cylinder seen from the top. It looked fine and I could use whatever collider I needed, but when I scaled it up I noticed that it seems to have a really low level of detail. See this screenshot for example:
I almost wouldn't call it round. I feel like I'm missing something really obvious here, but when i googled it, no solutions came up. So, what can I do to increase the polygon count? And is there a better way to create a simple 2D circle?
Thank you.
Please correct me. What do you want is a really smooth circle? Does it matter if it is a mesh or just a representation such as an image?
$$anonymous$$ake a quad and texture it with an image of a circle. Change the material of the quad so that it supports transparency. If the background of the image is transparent, you'll see a circle.
Then change the collider on it to a CircleCollider2D.
_GLxd: The OP doesn't want to use "image sprites," which sounds like a fancy way to say they don't want to use a texture.
I'm assu$$anonymous$$g they will either say why textures won't work; or they just heard "image sprites" were bad from some random guy (making this a really boring Q.)
Ah, I thought "image sprites" referred to a 2D sprite that Unity has, as opposed to a 3D quad with a texture.
Based on all comments so far.. sounds like: 1. Use a large sprite as _Gkxd just said.. AND make sure "mipmaps" are enabled for that sprite (default in U5, wasn't in U4), that way it looks good when small as well.
Answer by saschandroid · Apr 15, 2015 at 09:26 AM
Creates a 'circle'-mesh with radius 0.5 and variable number of circle points:
public void MakeCircle(int numOfPoints)
{
float angleStep = 360.0f / (float)numOfPoints;
List<Vector3> vertexList = new List<Vector3>();
List<int> triangleList = new List<int>();
Quaternion quaternion = Quaternion.Euler(0.0f, 0.0f, angleStep);
// Make first triangle.
vertexList.Add(new Vector3(0.0f, 0.0f, 0.0f)); // 1. Circle center.
vertexList.Add(new Vector3(0.0f, 0.5f, 0.0f)); // 2. First vertex on circle outline (radius = 0.5f)
vertexList.Add(quaternion * vertexList[1]); // 3. First vertex on circle outline rotated by angle)
// Add triangle indices.
triangleList.Add(0);
triangleList.Add(1);
triangleList.Add(2);
for (int i = 0; i < numOfPoints - 1; i++)
{
triangleList.Add(0); // Index of circle center.
triangleList.Add(vertexList.Count - 1);
triangleList.Add(vertexList.Count);
vertexList.Add(quaternion * vertexList[vertexList.Count - 1]);
}
Mesh mesh = new Mesh();
mesh.vertices = vertexList.ToArray();
mesh.triangles = triangleList.ToArray();
}
Wow, neat. I'm currently not able to test this, as I'm out traveling, but I'll try it when I get home. How is it for performance?
Answer by Calum1015 · Apr 11, 2015 at 05:41 PM
You could get on a modelling program and do it yourself, honestly there's not much you can do other than sprites/textures and custom mesh's. You might be able to change the camera from Perspective mode to Orthographic then move it along the Y axis, but I don't know if that will change the quality, I mean you won't see all th lines if the cylinder is further away. Also, About the only way to make a 2d circle properly in Unity 2D is sprites.
Answer by pankrac2 · Apr 11, 2015 at 04:21 PM
Use sphere?
As things stand he's getting a circle by looking at a cylinder end on. If you're going to do that then I$$anonymous$$O using a sphere ins$$anonymous$$d makes a lot of sense.
Sphere won't be more detailed + you won't be using half the mesh of it (backside) and it will make some possibly unwanted shading