2D Or Not 2D – Creating 2D Games With Unity3D Part 3

本文介绍了一种使用Maya构建3D模型并将其导入Unity3D以创建2D游戏背景的方法。通过调整Maya设置和相机视角,确保了从3D到2D的准确转换。

2D Or Not 2D – Creating 2D Games With Unity3D Part 3

Posted January 20th, 2011 in  TutorialsUnity3D 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 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 a .png, rebuild the sprite atlas in Unity and test out the changes.

I know what you’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 would 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 should 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 make 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 expect 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 should 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 should 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 particular gameplay plans. 3D can complicate things rather quickly, especially 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.

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

课程设计报告:总体方案设计说明 一、软件开发环境配置 本系统采用C++作为核心编程语言,结合Qt 5.12.7框架进行图形用户界面开发。数据库管理系统选用MySQL,用于存储用户数据与小精灵信息。集成开发环境为Qt Creator,操作系统平台为Windows 10。 二、窗口界面架构设计 系统界面由多个功能模块构成,各模块职责明确,具体如下: 1. 起始界面模块(Widget) 作为应用程序的入口界面,提供初始导航功能。 2. 身份验证模块(Login) 负责处理用户登录与账户注册流程,实现身份认证机制。 3. 游戏主大厅模块(Lobby) 作为用户登录后的核心交互区域,集成各项功能入口。 4. 资源管理模块(BagWidget) 展示用户持有的全部小精灵资产,提供可视化资源管理界面。 5. 精灵详情模块(SpiritInfo) 呈现选定小精灵的完整属性数据与状态信息。 6. 用户名录模块(UserList) 系统内所有注册用户的基本信息列表展示界面。 7. 个人资料模块(UserInfo) 显示当前用户的详细账户资料与历史数据统计。 8. 服务器精灵选择模块(Choose) 对战准备阶段,从服务器可用精灵池中选取参战单位的专用界面。 9. 玩家精灵选择模块(Choose2) 对战准备阶段,从玩家自有精灵库中筛选参战单位的操作界面。 10. 对战演算模块(FightWidget) 实时模拟精灵对战过程,动态呈现战斗动画与状态变化。 11. 对战结算模块(ResultWidget) 对战结束后,系统生成并展示战斗结果报告与数据统计。 各模块通过统一的事件驱动机制实现数据通信与状态同步,确保系统功能的连贯性与数据一致性。界面布局遵循模块化设计原则,采用响应式视觉方案适配不同显示环境。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值