Search Unity

Creating a 3D game with 2D graphics.

Discussion in '2D' started by Fellshadow, Jan 30, 2014.

  1. Fellshadow

    Fellshadow

    Joined:
    Dec 2, 2012
    Posts:
    169
    So, I asked this question on Reddit and got a lot of helpful answers, but I also wanted to get some feedback from the people here as well.

    I've currently got a 2D game in Gamemaker that I've spent many hours creating, but the more I worked on it, the more I realized that it was conceptually and mechanically a 3D game that just looks 2D. This made me think that I should switch to Unity as I thought that it may be easier to make it this way, even though I'm less experienced in this engine. I just wanted to get some feedback from people with experience in the engine as to whether or not what I want to do is possible, and how difficult it would be.

    Some of the features I want to have / currently have in my game (In Gamemaker) are:
    -Use of all 3 dimensions but maintaining a 2D look. The player can move behind, in front of, and on top of different objects or terrain.
    -Large open world. I used chunk based loading from external files to create a seamless exterior world. Think Skyrim; no loading or visible transition between exterior areas, only when moving from exterior to interior.
    -Realtime lighting and shadows on sprites.

    Would any of the new 2D features in 4.3 help with this? People on Reddit mentioned that Unity Sprites can't be used in 3D, so I'd have to use quads and apply textures to them. Would the rest of the Unity 2D features also not work in 3D?
    Would it be necessary/better to buy the 2D Toolkit?

    Here's an older screenshot of my game, just so you get a feel of the camera angle and graphic style that I'm going for. I want to keep the 2D "feel" of this screenshot, but have the features mentioned above.

    Sorry for all the questions. I've spent so much time working on the game already, that I want to make sure that if I switch engines, I'll be able to have all the features I'd like.
    Thanks in advance.
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Everything's possible, it's a matter of programming it. I didn't see anything in your description that seemed excessively difficult.

    That's entirely wrong; sprites are basically just quads in 3D space. (Of course that's oversimplifying, but still they are meshes and can be positioned, rotated, etc. the same as any other object.)

    --Eric
     
  3. Fellshadow

    Fellshadow

    Joined:
    Dec 2, 2012
    Posts:
    169
    Thanks for the reply!

    So even if I'm using the 2D Sprite Object it can still be placed and rendered properly in 3D? That's great! Then it wouldn't be difficult at all to make it move around and interact with the environment.

    I'm also kind of worried how the camera rendering works. I would like to place my character sprite, for example, at a 90 degree angle to the ground tiles, and then place the camera looking down at the same angle it is in the 2D game (Which I guess would be around 45 degrees). If this is done with a perspective camera, the sprite will be viewed at an angle. If I use an orthographic camera, would it still look like its being viewed at an angle, or would it look as if its straight on? Would I have to go the Legend of Zelda, A Link Between Worlds route, and rotate all my characters and objects 45 degrees as well, to see them straight on? I'm trying to avoid that, if possible, because I wanted to add the functionality to rotate the camera in 90 degree angles around the character and it looks odd if all the walls and such are leaning, haha.
     
  4. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    No, it would look like it was from an angle. That is basically how "isometric" games are made. They are off-angle games with zero-perspective.
    What they did in A Link Between Worlds wasn't because of using an orthographic view at an angle, in fact, they we're looking straight down, they did that so the map itself could feel like it was 2D top-down, but while faking a sort of forward looking direction so you could still see all the art assets nicely. Just like in the older 2D Zelda games, you're looking straight down at all these sprites, but the sprites are design in a way so that you can still see the front of them.

    Orthographic is without perspective, but angles still happen, just that same-angles appear exactly the same, no matter their position on the screen. Test it out yourself and you'll see if you like it or not!

    If you don't want your sprites to appear off-angle though, then yeah, you'd need to do the Zelda trick (though much easier with sprites, just have their X rotational axis set to the reverse of the camera's rotation.
     
  5. Fellshadow

    Fellshadow

    Joined:
    Dec 2, 2012
    Posts:
    169
    Ahh, I see, thanks for the informative response!

    So, to get the same kind of look as the screenshot I provided, the only real way to go about it is to have my sprites rotated at a 45 degree angle away from the camera?
     
  6. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    If you want to be using physics to move your character around on the ground and bump into things, yeah, pretty much, it would probably be the most versatile and simple method I could think of.
     
  7. Fellshadow

    Fellshadow

    Joined:
    Dec 2, 2012
    Posts:
    169
    Well, I guess I could just scratch the idea about being able to rotate the camera around the character then, lol. I think it would look too odd when you see that the walls you were looking at from the front aren't vertical.
    Would take way too many assets anyways.

    How would you recommend creating the world? In the Gamemaker engine, the rooms were saved as xml files, so I wrote a separate program that searched through the xml file, found all the objects and tiles, and broke them up into 1024x1024 chunks. I then did standard chunk loading in game to load the world from the files.
    I have no idea how to go about doing this in Unity though. I'm not sure if I can even build the world in the Unity editor and have the game load in chunks.
     
  8. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    Gamemaker is incredibly old. You really don't need the chunk loading for a game like this unless you want it to run really well on 12 year old hardware... Unity automatically stops rendering the textures that are off screen, so no chunk loading needed anyways, as far as textures go. For scripts on things offscreen, or even whole objects, you can Enable/Disable them easily with OnBecameVisible/Invisible(); If you'd like.

    If you wanted rotating, so basically a Sprite in a 3D world with some 2D look to it, I would just say to develop a 2D style with 3D objects, so build 3D objects that fit your 2D designs, and give them that texture, with self illuminated materials that aren't affected by lighting (or maybe just shadows). Then from orthographic views, it should still have the look you're going for, but will support rotating around it for a nice effect, almost like FEZ in a sense.
     
  9. Fellshadow

    Fellshadow

    Joined:
    Dec 2, 2012
    Posts:
    169
    Oh really? Even Skyrim uses a form of chunk loading though, so I kind of thought it was necessary for most games.

    I don't really have enough experience with modeling to make 3D objects, or I would do that for sure. I also have a few artists that have worked hard providing all the 2D artwork, and I don't want to just be like "Yeah sorry, I don't need you anymore!"

    I've actually messed around with the look I can get in game. Here are some screenshots of it.
    The only annoyance I've come across so far is actually placing all the tiles down. It seems like it will take forever, since I have to make an empty game object and then apply the correct sprite from my tileset to it, then put it in the perfect position (I couldn't find any snapping option besides holding CTRL), or duplicating an already made game object and changing its sprite. Is there a better way to go about doing that, I wonder?
     
  10. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    Skyrim is a massive open world 3D game with millions of polygons and gigabytes worth of compressed textures. So it needs to load chunks to remain persistent. This is a game that is entirely low res pixel-art textures that take up very little memory, and almost no geometry apart from basic colliders. Even a somewhat old smartphone should be able to load all your assets into memory if it wanted and run fine.

    That looks fine. For snapping, what you want to do is create an example object in the scene at the 0,0,0 mark, that has your colliders setup on it all nice and whatever else. Then drag it from your Hierarchy into your Assets folder (preferably a sub folder such as Assets/Prefabs/Terrain, or w/e. Then any time you want that in the scene, just drag it out from your Prefabs folder, and it's all ready to go. Any changes you make to the Prefab will propagate to all of the rest that are placed in your scene.

    And since you're using the 2D sprite system, which by default sets your pixel to unit ratio as 100. So assuming you're using power of 2 textures ( which you should be) then your snap settings should be set to something like 0.16 or 0.08, this will allow you to easily move everything around so it always matches up perfectly. And if you need to lay out large swaths of terrain, you can select multiple objects, duplicate, and move them all at once since they will be selected after the duplication.
     
  11. Fellshadow

    Fellshadow

    Joined:
    Dec 2, 2012
    Posts:
    169
    That's.....a very good point.

    I actually changed my pixel to unit ratio to 64, since all my tiles were 64x64. It just made more sense to me. Should I switch it back to 100?

    For the most part, I seem to have gotten the hang of things though. I'm just trying to figure out how to make the corners of the plateau a little bit more believable. I can't use the corner textures in the screen shot, due to the transparency at the bottom (the previous corner tiles didn't use the full 64x64, as I was relying on the layers beneath to make it look believable).
    I've got two ideas, so far:
    -Just turn walls at 45 degree angles as well. The only problem with this is that the walls then aren't long enough to cover a full space, I'd have to stretch the wall piece out to make it reach the next tile.
    -Bend a plane so that it slightly cuts off the corner. Probably the easiest way, although less natural looking than the 45 degree walls, I think. The problem is trying to match ground tiles placed above it so that the edges line up.

    What do you think? Is there a better way I'm overlooking?

    Also, thanks a lot for all the advice and answering all my questions. You've been a huge help.


    EDIT: I'm actually getting this weird graphic error. I don't know what's going on, but some of the walls behind the character are getting rendered in front of the character for some reason. Here's a screenshot:
    $graphicglitch.png
     
    Last edited: Jan 31, 2014
  12. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    Nah, you can leave it 64, that's what I did too. Just have you snap settings be something like 0.1, since 1 unit is a power of two number (64).

    You have to use the sprite layering system. The sprites don't render based on Z distance, they render by layer in the Sorting Layer option, and the Order in Layer with respect to the layer it's in.

    http://gyazo.com/9f194e9aa7d67fcb12224b5daf553d2c.png

    That could be a problem for you actually, it may be better for you to just use Quad's with the sprite texture on them instead... Or you could probably modify the sprite shader to support z-depth.
     
  13. Fellshadow

    Fellshadow

    Joined:
    Dec 2, 2012
    Posts:
    169
    Ah ok, thanks!

    I guess I'll look into adding z-depth into the sprite shader. I have very very little experience with shaders, but I feel like I've added z-depth into one before...
    I was going to have to mess around with the shader anyways, to get it to support lighting and dynamic shadows.

    Which brings up one final (hopefully) question. I've already researched adding lighting and shadows from sprites in Unity, so I know its possible to do that. There was one flaw in those, however; they didn't support casting shadows from the side of the sprite. I just wanted to know if I made sure each sprite also had a side sprite, would I be able to tweak it so that if the light is at a certain angle to the sprite, it will use the side sprite instead?
     
  14. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    You could through a script on the player, by using Vector3.Reflect to see which side of your character has the least angle towards the light, and setting the light to not be able to affect the sprite with more angle.

    http://docs.unity3d.com/Documentation/ScriptReference/Vector3.Reflect.html

    You'd call it once for each side, the inNormal you'd use would be the sprite's transform.back, most likely, or transform.forward. And the inDirection would be the light's transform.forward.
     
    Last edited: Jan 31, 2014
  15. Fellshadow

    Fellshadow

    Joined:
    Dec 2, 2012
    Posts:
    169
    Well, I want the light to affect the sprite. I'm just talking about the shadow it's casting. the light is in front of or behind the sprite, the sprite will properly cast a shadow on the the ground. However, if the light is to the left or right of the sprite, no shadow (o a very thin line) will be cast. Essentially, when the light is to the side of the sprite, I want it to cast the shadow based off of a side sprite provided.

    Also, I've managed to add z-depth to the sprite shader, but now I've run into another issue....
    $graphicglitch2.png

    EDIT: I did it! I enabled AlphaTest so that it only renders pixels that are greater than a certain alpha value.
     
    Last edited: Jan 31, 2014
  16. littletuskar

    littletuskar

    Joined:
    Mar 29, 2017
    Posts:
    1