- Home /
How to draw a line around multiple/child objects?
Hi all, I hope someone can give me a point in the right direction with the following as I have had trouble finding any examples/techniques:
I have a parent object which contains a number of child objects (Tiles) which can be placed in any shape but they are all still touching. I need to draw a line around the edge of all the child items together. For example, if the tiles make an L shape, the line would be drawn around making an L rather than around each tile separately.
I've had a couple of thoughts to solve this:
Get the vertices of all child items, remove the inner items, keeping the edge vertices and then drawing a line between. No idea how to find the edge items though and getting them in the right order (clockwise) may be tricky.
Generating a mesh from the child object mesh's and then applying a sillouette shader?? Not sure how to do this though but it feels the right way to go. I have the shader but not sure how to get meshes from sprite renderer components.
I saw a plugin that draws lines around groups of objects but I can't seem to find it again now.
Has anyone done this before??
I could simply fill all the tiles with a colour to give a different feel but its not really what I am going for.
Later down the line I would also like to make a polygon collider using the same shape.
Thanks in advance!
Peter
Hi, are your tiles all of the same size ? If so, you could use a logic representation of the grid composed by them: imagine a table[,] containing booleans representing the presence or absence of a tile at a tile position. Then, you can easily detect edges by comparing table elements (if this tile is "on" and tile on the right is "off", then there is a line there).
Then, you could use $$anonymous$$eshTopology http://docs.unity3d.com/ScriptReference/$$anonymous$$eshTopology.html to create a mesh composed of lines (if lines are what you want: I guess those lines are 3D lines but always rendered 1 pixel thick, like Debug.DrawLine() )
If you want to tackle #1, I outline a solution in this answer. It would be a bit of work:
http://answers.unity3d.com/questions/804696/combining-shapeslist.html
Note for squares, the point in rect and intersection of segments are much easier to calculate than in the general case.