1
\$\begingroup\$

From my previous post where I search solutions to have animated characters in an isometric world (using 2D engine as base) arised this question.

I'd like to create and instantiate 2D sprites from 3D models, using Unity, at runtime, in order to use them as they were sprites, ordering them by depth, etc.

There are already unity scripts (maybe using 3d party software) that make this, like Sprite Maker. How is this done? (You have to pay to get the Sprite Maker). Anyway, I need to do it at runtime, instead of baking a spritesheet.

How do I do it? Is it posible?

Other solution, instead of converting it to sprite, is being able to sort the 3D model as it were a sprite. But how?

\$\endgroup\$
  • \$\begingroup\$ Not runtime solution, but it converts 3D models to sprites. assetstore.unity3d.com/en/#!/content/15688 \$\endgroup\$ – SanSolo Oct 29 '15 at 12:27
  • \$\begingroup\$ The approach I would try is to render the sprites to a render-target (once) and then use the result as a texture for a 2d sprite. No idea if that is feasible, though. \$\endgroup\$ – Philipp Mar 31 '16 at 21:13
1
\$\begingroup\$

Finally I found a solution. It is posible to order in the same layer 3D and 2D objects!

Old answer:

To do it there are two simple steps - Add a sprite shader (diffuse or not) to the 3D model mesh object - Sort in layer via script: GetComponent().sortingOrder = z; Found information here

No. That finally did not work properly. But I found an other solution: as the objects are displayed always, no matter if they are 2D or 3D, depending on Z in ortographic perspective (minor Z means more above), my solution was to put my 3D model into a container (empty object). I gave to this container a very small Z scale: 0.0001f. So it really seems to be 2D, while I still can rotate the model as it is a child object with no troubles. After that, to order my objects depending on the diagonals of my isometric world, I just decreased, for each consecutive diagonal, the Z component by -0.0001f*diagonal. That worked like a charm.

Decreasing by a small number allows to use lights as child objects of 2D sprite-diffuse shadered objects, as the sprites/models don't move too much far away from the background to notice it.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.