Draw free 2d shapes dynamically in unity - unity3d

I want to be able to draw any 2d shape dynamically in 2d world. My games has moving elements, looking like circle when alone, that can fuse and make complex shapes when getting close together. The elements can still move and thus separate or modify the shape.
How can I draw that with Unity? I don't think the usual sprites can do the trick.

I believe you can do that with shaders (sounds complex to me, but utilises GPU).
Or...
Modify sprite's vertices to introduce streching of the texture.

Related

Projecting procedural attack telegraph decal in Unity

I'm creating an isometric 3d brawler in Unity. I'm trying to draw a telegraphing "attack area" effect on the ground (Meshes, not Unity terrain), from an arbitrary polygon (including curved lines.), based on Vector3 points.
I figure I need to use the Unity decal system, but I'm not sure how to generate the area texture procedurally, especially since it needs to match points in 3d space. Here are a few examples of the effect I'm looking for.
Thanks for taking your time to read this :)

2D Sprites in Isometric 3D Unity Project

The project works under a isometric orthographic camera, in a 3d space using 2d sprites.
What we are using are billboarding sprites into 3D colliders to archieve the 3d feeling.
The problem is that we don't really believe the way we are doing it it's the most optimal. We are also having problems introducing high areas, because we need to reply the sprite form in isometric perspective as colliders.
Because we are using 3D world, the tilemaps tools conflicts with the other vertical sprites.
We can not use a entire 2d floor billboarding sprite because that suposes to have a huge vertical sprite in front of the camera, so we can not display the others.
We are just researching for a solution before to change to a 2D world.
If you plan on sticking with isometric in 3D, get rid of the tilemaps entirely. They are just going to give you a headache and make your game lag itself to death. If you want to convert to entirely 2D isometric, you can stick with them as they would work fine. Now, a few comparisons between the 2D and 3D approaches, and how best to approach them. This is a jumbled list of drawbacks/advantages to each type, so it's more of a ramble after this point than an answer, but I couldn't be more specific without knowing more about your project's overall requirements and specifications.
Unity recently added Isometric Tilemapping as a dedicated feature. So, if you choose to fake it with 2D, your life will be a lot easier.
Controls are a lot easier in 3D, as the physics won't ever have to be
faked.
3D allows foreground objects to automatically cover up background
objects without having to add an arbitrary system to achieve the same
effect.
2D is fundamentally faster than 3D, and if you're aiming for mobile,
that's going to be very important to your project's success.
3D allows you to rotate your camera if you design it right. (Check out Don't Starve Together for an example of this design).

What is the most efficient way to create a group of 2D tiles with 2D colliders in Unity3D?

First of all, I am using Unity3d.
What is the most efficient (in terms of memory) way to create a group of 2D tiles with 2D colliders using a texture atlas (and tile data)?
Background Info:
I am working on a 2D terrain generation asset. It is a very similar generation style to Terraria's random generation. Currently, each tile is being instantiated as a separate GameObject. As I now know, this is extremely inefficient, and I should use a texture atlas and tile data instead. Here is a link to a tutorial I have been following that deals with this in 3D: http://studentgamedev.blogspot.co.uk/2013/08/unity-voxel-tutorial-part-1-generating.html
The problem is that mesh colliders are 3D colliders; 3D colliders CANNOT collide with 2D colliders. Currently in Unity, there are no 2D colliders (that I am aware of) that have the properties of a mesh; I need to dynamically change the 2D collider to adjust to the positions that contain tiles. How am I supposed to develop an efficient 2D tile system using 2D colliders?
Here are some of my ideas of techniques that may work:
Add a box collider 2D component to the chunk GameObject for each tile in the chunk.
Somehow dynamically use a polygon collider 2D to stretch over all solid tiles.
I have read through several threads and cannot find a good approach for this problem.
I am mostly looking for a proven technique/approach to this issue, but I am open to any suggestions or techniques. I am happy to provide clarity as needed. Thanks for any answers! I appreciate the time you put in to answering my question -it helps a ton!
As you rightly said, 2D colliders do not work with 3D colliders. The correct approach would be to pick one or the other.
If you are mixing 2D and 3D objects, go with 3D. You can restrict the axes in which your objects are affected by physics as explained in this answer.

Simple rectangle in Unity3D

There's plenty of tutorials which explain how to add and manage image objects. But what if I want to add simple rectangle with plain white color? May I do it similar to adding 3D objects? I see no rectangle option under 2D Object in GameObject menu.
I know that I may do it by script, but isn't there any simpler solution? Or maybe I should use 3D Object Cube instead?
For a rectangle (ie a 2D cuboid) you add a 3D object that is a Quad which is a 3D object with a size of 0 in one plane, in effect making it a 2D sheet.
See also:
http://docs.unity3d.com/Manual/PrimitiveObjects.html
Quads are most often used as backdrops to 2D games. Once you have the quad you can then change its material properties to set it as a single plain colour.

Unity3D Repeating pattern applied 2D Mesh with collider

What is the proper way of creating 2D Mesh with collider?
All I want to do is create some shapes (not very simple like triangle or rectangle) like slide or rounded rectangle. And I want to define a repeating pattern inside it to fill and reduce memory. Lastly I will need a collider around my shape.
Create the entire thing in a modeling program like Blender... same as you would for a 3D model, but all of your shapes/meshes will be flat. Create your textures the same also... all in your modeling program. Then save your file (.blend for Blender) to your Unity assets folder. Now switch back to Unity and drag/drop the prefab that is created form the .blend file on to your scene. Change the renderer if you want (I use Mobile Unlit, or Unlit Transparent most of the time).
Works just like a normal 2D sprite now... but the texture will repeat and you can make whatever shape you want in your modeling program.
For the collider, you can add any type of collider you want. If your shape isn't standard, you'll probably want an Edge Collider 2D or a Polygon Collider 2D.
I would suggest you the following:
Create a polygonCollider2D directly in unity as you need it
Add a mesh filter and a mesh renderer
Add a custom script made by yourself, in which you convert the Collider polygon to a mesh (Mesh that will be used on your MeshFilter at runtime).
3.1. In order to do this, just copy the vertices of the polygon
3.2. Use the triangulator class in this link to help you create your mesh (http://wiki.unity3d.com/index.php?title=Triangulator)
Enjoy
If you want to see the custom script find it here: http://answers.unity3d.com/questions/835675/how-to-fill-polygon-collider-with-a-solid-color.html