2d or not 2D-creating 2D games with unity3d Part 3

Source: Internet
Author: User

2d or not 2D-creating 2D games with unity3d Part 3 posted January 20th, 2011 in tutorials, unity3d by Tim Miller

My next game is going to be 2D, but the backgrounds will be forced perspective to give the scene a 3D appearance. before the artists starts artifying the final backgrounds in Photoshop, I want to make sure the levels are properly laid out for gameplay-the last thing I want is to waste the artists time with re-dos for object position fixes. since my background is primarily in 3D level design, I decided to blockout the levels in Maya and then render them out to 2D textures. i'm still in the early stages of working out of the process, but so far there are already some noticeable advantages to this workflow. the main advantage is that I can easily make adjustments to object positions in Maya, render the scene to. PNG, rebuild the sprite atlas in unity and test out the changes.

I know what you're re thinking-since I have 3D levels blocked out in Maya already, why not use those assets in unity? Unity is a 3D engine after all so it's pretty easy to import the models directly into the scene. after a few tests rendering the 2D scenes from Maya and seeing how they looked in unity, I decided to see if using full blow 3D levels wocould be the better way to go.

Maya setup

Note that even Tho I'm using Maya, you should be able to apply these setups to any 3D app. Before you import 3D objects from Maya, you need to confirm some Maya settings:

  1. In Maya, go to window-> Settings/preferences and click on Settings
  2. Set the Up axis to Y since y is up in Unity
  3. Set the linear working units to centimeters. A 1x1x1 centimeter cube in Maya is the same size as a 1x1x1 Unit Cube in unity.

You can test that the above settings are correct by creating a 1x1x1 cube in Maya and then importing it into your unity scene. create a 1x1x1 cube in unity, position the 2 next to each other and they shoshould be exactly the same size.

The next thing I did in Maya was to setup the perspective camera (persp) so that its positioned and angled exactly how I want the scene to be viewed in the game. here's a pro tip: once you have the camera positioned exactly how you want it, select the camera, move the cursor to frame 1 on the Time Slider, and then set a keyframe on it (animate-> set key or just press's 'on the keyboard ). also Mak E sure that the "auto keyframe toggle" (located in the lower right hand corner on the Time Slider) is off. now you can freely rotate the camera while building out your 3D scene, and when you want to see what the scene looks like from the game camera, just move the cursor on the time line from frame 1 to frame 2 and then back to frame 1 and your camera will snap back to the frame you set. awesome!

Another cool trick is to set the render settings image size so that it's the same size as what you need CT to see in the rendered game view. basically it'll add a box to the perspective camera that will show you exactly the area that will be rendered. note that I'm using Maya 2008 so your options may be different.

  1. In Maya, change to the rendering menus (drop down in the upper left hand corner)
  2. Render-> render current frame. This will open the render view and render whatever is visible in the active camera.
  3. In the render View window, go to options-> render settings
  4. Under image size, change the width and height to match your games render view. For example, if you're making an iPhone game you might set this to 480 by 320.
  5. Now if you look back at your Maya scene, you shoshould see a 480 × 320 rectangle.

With the above correctly setup, you should be able to get an accurate view in Maya of what your game will actually look like on the device. here's what my scene looks like (click to see the full sized image ):

Unity setup

Once you have a level blocked out in Maya, the next thing is to bring it into unity and set everything up so that it looks the same.

  1. To import the level into unity, all you have to do is save the Maya file into your project's asset folder (eg. Assets/models ).
  2. Drag the level from the models folder into the scene hierarchy and position the model in the scene.
  3. Change the camera in your unity scene from orthographic to perspective if it's not already.
  4. Adjust the camera's position, rotation and field of view so that the scene appears exactly has it does in Maya. this will require a bit of trial and error adjustment but eventually you shoshould be able to dial it in exactly.

Prior to this little experiment, my game had been setup to be entirely 2D with objects only moving on the X and Y axis. to make the game truly 3D, you have to bring the Z axis into play. after spending the better part of a day converting my 2D game to 3D (just to test out my theory), I decided that 2D is actually better for my participates ular gameplay plans. 3D can complicate things rather quickly, espe Cially when dealing with touch events on the iPhone. But none of the above setup is wasted! Because of everything I set above, I can easily go back to my original plan of rendering the 3D scene to a 2D Texture in Maya.

Conclusion

This concludes Part 3 of the series. I had been planning to take you through the creation of a simple 2D platformer game in this installment, but I 've been super busy trying to get our new game ready to show to the press at GDC. instead Part 3 went over some of the techniques I'm using to make the new game which hopefully you'll find useful.

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //

Http://www.rocket5studios.com/tutorials/2d-or-not-2d-creating-2d-games-with-unity3d-part-3/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.