游戏邦在:
杂志专栏:
gamerboom.com订阅到鲜果订阅到抓虾google reader订阅到有道订阅到QQ邮箱订阅到帮看

分享使用Unity制作游戏关卡的教程(2)

发布时间:2013-08-17 14:28:49 Tags:,,,

作者:by Matthias Zarzecki

本文是“使用Unity制作《The Fork Of Truth》的关卡”系列的第二部分。

第一部分中,我们介绍了如何使用Unity的Unity Terrain制作基本场景。在这一部分,我将继续介绍场景对象以及它们的设置。

Benjamin(from pladinstudios)

Benjamin(from pladinstudios)

基本设置

制作关卡有两种途径:一是使用模块化贴图系统(想象一下“乐高积木”);二是纯手动制作。《Momonga – Pinball Adventures》和《Nikko RC Racer》走的是第二条路线。手动制作虽然具有很大的自由度,但太费时间,这就限制了游戏的规模;另外,手动制作关卡的过程艰难而费时,进而限制迭代和实验的次数。

momonga_011(from matthewongamedesign)

momonga_011(from matthewongamedesign)

maro kart(from from matthewongamedesign)

Nikko RC Racer(from from matthewongamedesign)

而模块化贴图就不同了。使用这种方法不需要手动制作资源,而是先制作一系列“积木块”,然后再把它们组合起来。你可以使用一小堆积木做出各种各样的东西。这种方法的最大优势也许是,允许是关卡制作过程变成一种快速构建-测试-改进的循环。设置(或改变)整个场景是很容易很迅速的,这就使得短时间内测试一个关卡的不同变体成为可能。

贴图

游戏中的一切物品(建筑、木箱、围栏)都叫作“对象”。各个对象都必须能够轻易地融入游戏,并且它的大小对齐到贴图。因为所有对象都是这样设置大小的,所以游戏中的所有对象都彼此保持对齐。事实上,一个对象就是Autodesk 3DS Max中的一个3D 模型。所有对象都有自己的文件,其中包含它的一切属性。下图就是一个对象:

model_watchtower(from from matthewongamedesign)

model_watchtower(from from matthewongamedesign)

这种瞭望塔在关卡中多次出现,可以与其他对象如围墙、木箱、木桶等一起使用。注意,这个对象的轴点是在它的底部。这样设置轴点便于把物品放置到地面,因为它们的零点也已经在那里。我们把这个对象保存在Unity中的一个名称为“模型”的文体夹中。当使用Unity制作关卡时,对象可以自动导入到Unity中。当然,上图中的瞭望塔只是一个简单的草样,还不是最终版。它已经有基本的大小和形状了,但我们仍然要制作最后的3D模型。我们已经可以把这样的模型布置到关卡中了,也就是把3D模型转化成Unity的预制件。这些“预制的对象”就是我们用来构建关卡几何的“积木块”。

我们用Merlin’s Prefab Lab(游戏邦注:这是一个Unity插件,可以自动生成所有3D模型的预制件)自动生成预制件。当你改变源3D模型时,Prefab Lab会更新预制件内的模型,同时保留相关性。当预制件更新时,该场景中的所有对象也将升级。

命名规范

团队的所有成员都可以使用、修改和制作对象。这就要求所有对象都有清楚的名称,这样才不至于在庞大的对象库中寻找某个对象时感到困惑。命名对象的方式有很多种,我们的要求是,允许我们在项目文件夹中寻找对象。无论你使用什么规范,请保证对所有对象都始终统一地使用它。

举一个例子:

“Tree Broad Leaved 01 3×3 Green”

上述命名的结构是“对象-修饰词-变体顺序号-大小-视觉特性”,首字母大写,单词间空一格。“对象”是指物品类别(游戏邦注:例如“树木”、“岩石”、“房屋”);“修饰词”是对物品的主要形容,(如“大”房子);修饰词后跟着变体顺序号,也就是告诉你它是同一个对象的第几个变体(如,2表示2个不同的“岩石 大”);“大小”是告诉我们该对象的贴图是多大,这样我们不需要把它添加到场景中就能立即知道它有多大了。这种命名组合把所有相关的对象放在一起,这样我们就能轻易地在对象库中寻找某个对象。

放置对象

要在场景中放置对象,首先打开项目文件夹中的预制件,然后放进场景中:

editor_01(from from matthewongamedesign)

editor_01(from from matthewongamedesign)

editor_02(from from matthewongamedesign)

editor_02(from from matthewongamedesign)

就是这样!对其他物品进行同样的操作,关卡很快就填满了。然后简单地调整对象的位置、旋转它们,直到得到满意的效果。

editor_03(from from matthewongamedesign)

editor_03(from from matthewongamedesign)

组合对象

连续放置对象也是相当实用的。因为所有对象都已经做成“网格”对齐的样子,所以可以轻易地对齐在一起。我们可以非常迅速地制作出农田等场景:

field_01(from from matthewongamedesign)

field_01(from from matthewongamedesign)

按下Ctrl键同时移动物品,把它填进网格里。对齐距离可以在Snap Settings(Edit -> Snap Settings)中调整。这对于制作围栏特别实用,只要几秒就可以做出很长的围栏:

fence_01(from from matthewongamedesign)

fence_01(from from matthewongamedesign)

另一种对齐物品的方法是,按下V键同时移动。这么做会把当前对象对齐到场景中的任意边界或点。我们还可以稍微旋转对象同时复制它们。稍微旋转各个围栏段再制作下一个围栏,可以做出旋转度更漂亮的围栏。

fence_02(from from matthewongamedesign)

fence_02(from from matthewongamedesign)

总结

使用基于贴图系统可以快速而简单地制作出关卡。

1、想象一下乐高积木,然后确定你需要的对象的贴图大小。

2、为了便于访问,请一致地使用命名规范。

3、使用预制件,以便对象更新的同时带动整个关卡的更新。

4、使用对齐功能可以迅速制作成组的对象。

我们将给最终版游戏制作至少12个关卡,内容会更丰富。为了提高工作效率,我们必然会使用这种方法制作所有关卡。

预告:在本系列的下一部分,我将介绍如何设置关卡的光照和声音。(本文为游戏邦/gamerboom.com编译,拒绝任何不保留版权的转载,如需转载请联系:游戏邦

Building Levels in Unity – Part 2 of 3

by Matthias Zarzecki

Hi!

It’s me again, Matthias of Paladin Studios. This is the second of three articles on how we built the level for the Kickstarter demo of The Fork Of Truth.

Part 1 deals with the basic environment setup in Unity, using Unity Terrain. If you haven’t read it yet, you can find it here. In this segment I’ll go into the environmental objects, and how they are set up.

Basic Setup

When you work on levels, you have two approaches: Using a modular tile-based system (think “Lego”) or building everything manually. Previous Paladin games, such as Momonga – Pinball Adventures and Nikko RC Racer use the build-it-manually approach. It gives you a great deal of freedom, but because the levels take more time it limits the scope of the game. The level construction also becomes an inflexible and time-intensive process, which hurts iteration and experimentation.

Tiles works differently. Instead of building every asset by hand, we create a set of building blocks, which can snap together. With a small set of blocks you can create some pretty wild variations. Perhaps the biggest advantage of a tile-based system is that it allows for a quick build-test-refine cycle. Setting up (or changing) an entire scene is easy and fast, which allows you to quickly test different variations of the level.

Tiles

Everything in the game (buildings, crates, fences) is an “object”. Each is made to fit easily into the larger game, and it’s sized specifically to align to tiles. Because all objects are sized in this way, they also align to the other objects in the game. An object is essentially a 3D model in Autodesk 3DS Max. Every object sits in its own file, and this file contains everything it needs. This is what an object could look like:

This proto-watchtower appears at several points in the level, and can be complemented with other objects like palisades, crates, barrels etc. Note that the pivot point is at the bottom of the object. That way we can easily place all objects “on the ground”, as their zero-points are already there too. We save this object in a folder titled “models” in Unity. From there, they are automatically imported into Unity, ready to be used within the game. The proto-tower is not final, it is a simple blockout. The artists have made this for a general indication of size and shape, but we still need to make the final 3D model. We can already start populating the level with this mockup, by turning the 3D model into a prefab in Unity. These “Prefabricated Objects” will be the building blocks we utilize to assemble the level geometry.

We automate prefab generation with Merlin’s Prefab Lab, a plugin that automatically creates a new prefab in Unity for every 3D model. When you then change the source 3D model, Prefab Lab will update the model inside the prefab while preserving the dependencies. When the prefab is up to date, all the objects in the scene will be updated as well.
Naming Conventions

Every team member can access, modify and create objects. As such it becomes necessary that each object is clearly named, so that there is no confusion in finding them in the huge library. There are many ways to name objects, but we are looking for a structured way that allows us to find the objects in the project folders. Whatever convention you choose, be sure to follow it All The Time.

We use this convention:

“Tree Broad Leaved 01 3×3 Green”

The structure is “Identificator – Modifier – Variant – Footprint – Optical Distinction”, written with capital letters and spaces between the words. It starts with the thing (“Tree”, “Rock”, “House”), followed by the main modifier (is it a large house? A small house?). This is followed by a running number, to allow for variants of the same thing (i.e. 2 different “Rock Large”). The footprint tells us how big an object is in tiles, so we immediately know how big it is without adding it to the scene. This naming scheme groups all related objects together naturally, so we can easily navigate the object library.

Placing Objects

To place an object in the scene, go to the prefab in your project-folder and drop in into the scene:

That’s it! Repeat that with a several other items, and the level will fill up quickly. Then simply tweak the position and rotation of the objects until you are satisfied with the results.

Snapping Objects

Placing objects in a row is quite useful too. Since all objects have been built to fit the “grid”, they can be snapped together. This way we can create farm-fields (and other constellations) in no time at all:

Holding down Ctrl while moving an object will snap it to the grid. The snapping distance can be adjusted in the Snap Settings (Edit -> Snap Settings). This is especially useful for fences. By just snapping them together we can create a longer fence in seconds:

Another way to align things is by holding down V while moving. This will snap the current object to any edge or point in the scene. We can also add slight rotations to the objects while duplicating them. By slightly rotating each fence-piece before creating the next one we created this nice rounded enclosure:

Conclusion

Using a tile-based system allows you to create levels quickly and painlessly.

Think in terms of Lego, and determine the tile sizes you want the objects to fit into

Name the objects consistently for easy access

Use prefabs to let your object updates propagate throughout the levels

Use the Snap function to quickly create arrays of objects

For the final game we will create at least 12 levels, all much larger and stuffed with content. They too will be built on the tile system, which is essential for an efficient workflow.

Next time: In the 3rd (and last) part of this series I’ll go into all the little things that make a level come together, like lighting and sound.(source:matthewongamedesign)


上一篇:

下一篇: