unity开发赛车游戏中文教程之一

所需积分/C币:50 2013-06-10 06:24:57 2.67MB PDF
收藏 收藏
举报

unity开发赛车游戏中文教程之一
The very basics. we will not go in depth with explaining the basic workflow and components in Unity. For that there are any other resources available at 非常基本的,我们不会深入解释ntg中基本的流程和组件,关于那些有许多其它有效的资 源 co/support/documentation/videol http://unity3d.cown/support/resources The User Manual and the Scripting Reference are valuable comp anions as you follow along this tutorial. We suggest that you visit these resources when ever you encounter a built in Component or function that you'd like to know ore about 用户手册和胸本参考是你在本教程的后续学习中很有用的伙伴。无论何吋,你在构建个组 件和函数时你都可以访问它们,如果你希望了解更多的东西得话。 The approach taken at first is that of code monkey see, code monkey do: You follow the instructions we give about putting a car together and changing it's variables. Hopefully you will be curious about how it works, learn something from seeing how everything is put together and do sowe investigation on your own Feel free to explore 开始的代码像是猴子编写的,包括你随后键入的这些由我们给出的和汽车放到一起的指令 并且可改变它变量值的代码,希望你会好奇它是如何工作,通过自凵做调查,如何把所有的 东西组装到一起来学习一些东西。使得探索变得自由一些。 In the last and longest section we dive more deeply into the actual code that akes the car drive 在最后和最长的部分,我们将更深入实际的代码,了解制造汽车的驱动器。 This is not a line-by-line walkthrough, but we will cover most of what is going onOne way to learn programming or improve ones skills is to look at a lot of code(supplemented by doing a lot of programming). we are certain that you will learn a lot from following this closely and getting an understanding of how the code works together 这不是一个线性的讲述,但我们尽量覆盖大多数内容,一种方法是通过看大量的代码学习和 提髙编程的技能(通过做很多编程练习),我们确信,你将接近)越来越理解一个代码是如 何·起⊥作的 包 Pro Standard assets sCenes Part 1: Assembling the Car E CompleteScene R TheTrack Download the zipped project folder from 回 scripts La Birds Behaviour 从下面的地址下载项目文档的压缩包 a Blohshadowcantroller http://unity3d.cown/support/resources/fi les/CarTutorialzip Start by opening the scene named CommpleteScene'. This scene has the car already setup, so you can try it out by pressing the Play button. This will show you the end result of what we are going to build 打开名称为“ Commpletescene”的场景,这个场景中已经放置了·辆汽车,所以你能试着 按下“Plag”按钮把汽车开出去,这就是我们最终将要构建的结果。 When you are done playing around, open the scene nanedTheTrack'. This scene contains what is needed to race, except the mnost immportant part -a car 当你玩完了,打开名为“ TheTrack”的场景,这个场景包含了我们需要的竞赛资源,除了 最重要的部分--一辆汽车。 Now drag the car model into the Scene. In the Project view you find it under Models,/car/ catamount№t 现在拖动一个汽车模型到场景中,你会在项目视窗中找到它,在 Models/Cav/ catamount. 目录下。 Depending on where you dragged the car, you probably want to change it's position to a more suitable one. I suggest that you change its position in the inspector to something like(860, 102.3, 878)and set it's y-rotation to 130 根据你拖动汽车的位置,你可能需要改变它 的位置到一个更适合的地方,我建议你在检 查视窗中改变它的位置到一些例如 (86O,102.5,878)这样的地方,并且设 置它绕Y轴的旋转角为13度。(注意不是与 Y轴的夹角) For the rest of the tutorial, this Gameobject will be referred to as ' Car' so you might as well rename it now 在剩余的教程中,这个游戏对象将被叫成“Ca”,所以你还不如现在就将它改名。 This is just the 3D model of the car. If you look in the Inspector, you will see that it contains a number of children such as the car's body, windows and wheels.It also contains two simple meshes that we will use for the car's colliders. Don't worry about them being visible for now, we will change that. Take soe time looking at how the car is arranged by different parts, and how they are related to each other in the hierarchy 这仅仅是一个汽车的三维模型。如果你查看检査视窗,你将看到一系列」对象,例如车身, 车窗和车轮,它也包含了两个简单的网格面,我们将用它做汽车的碰撞器。现在不要担心它 们会被看见,我们将改变它。花一些时间看看汽车的不同部分是如何放置的,以及他们如何 在彼此不同的层次上进行关联。 For various reasons, we want the car to be in it's own layer. With the Car Gameobject selected, go to the Inspector and select 'car' in the layers drop down menu. In the popup menu click ' Yes, change children to make the change apply to all Gameobjects in the car's hierarchy 由于种种原因,我们希望汽车将呆在它自己的层。选择汽车游戏对象,到检套视窗中并且在 下拉菜单中选择“car”这个层,在弹出菜单中点击“Yes, change children”,应用改变 汽车的所有子对象的继承 The Car GameObject has an Animation component attached by default. Since this is not something we are going to use, go ahead and do a little clean up by clicking the small wheel to the right of the Animation Component and selecting Remove component 缺省的汽车游戏对象有一个动画组件,由于在这里我们不用它做什么事,所以来吧,做一下 小清洁,点击小轮子动画组件的右侧,然后选择删除组件′。 Adding Collision增加碰撞 t区 Collide,_Bottom I ag Untagged Layer La Disco Select Reconnect Now we'l set up the collision A Trar storm conponents for the car to prevent it、下2 Position z 3 Ecale from falling through the ground when K d Y121 VE Collider Bottom IMesh Filter Mesh 围 Collide- botta m s Mesh Renderer running the scene. Instead of using+s Mesh Collider 回 Material complex mesh colliders based on the Smooth Sphere collisions Mesh 围 Collider botta m actual mesh of the car, we have setup Collider bottommat Shader Di fuse two meshes that are nuch simpler, Main Color FaSP(ETiR) (extI rPm Tiling offset that fit the top and bottom of the car seler For performance reasons, we are using these meshes as the collision model 现在我们将设置一个碰撞组件给汽车,以阳止它在场景中运动发生坠落时穿过地面,我们将 设置两个网格面米替代实际的复杂汽车网格面碰撞器,我们设置的两个网格面更简单一些, 它们将正好覆盖汽车的顶部和底部,出于性能的原因,我们使用它们作为汽车的碰撞模型。 Click on the Collider- Bottomm game object which is located as a child of the Car. 在汽车对象的」对象 Collider botton游戏对象上单击。 (先把这个对象下的组件都删掉,默认的都不是) Go to the Component/Physics Menu and click the Meshcollider to add one to the game object 到 Componεt/ Physics菜单上并且单击,给游戏对象增加一个网格面碰撞器 Meshcollider Click the Material dropdown-selector on the newly added Meshcollider conponent and select the Car physics mmaterial 在新埤加的网格面碰撞器上单击材料的下拉选择按钮并且选择Ca的这个物理材料。 Check the two boxes 'Smooth Sphere Collisions'and'Convex' 勾选两个检查盒“ Smooth Sphere collisions”(平滑球面碰撞)和“ Convex”(顶点) (网格面Mesh选择“ Collider botton”, Mesh renderer这个是给网格面加材质渲染, Mesh filte又是做什么的呢?) Since the colliders are going to be invisible, go ahead and remove the MeshRenderer and Mesh Filter Conponents from the Gameobject(Click the small cog wheel to the right of the Components and select Remove Component) 因为碰撞器将不可见,所以从游戏对象上删除 MeshRendereγ和 Mesh filte组件(单击组 件右边的小齿轮并且选择“删除组件”) Do the same as above for the collider- Top gamme object 参照上面对 Collider-Top游戏对象做相同的事情(网格面Mesh选择“ Collider-Top”) Shadow settings for the car oder汽车模型的阴影设置 We are going to change the shadow settings for the car model for two reasons First of all turning off shadow casting or receiving for objects that don't really need it is very good practice for performance reasons. Second of all we feel that it looks better to not have the car receive shadows. It might be more pleasing to the eye that shadows are not constantly appearing and disappearing on the car when it is traveling at high velocity under the level geometry. it's up to you what you prefer though. If you want more realistic shadow behavior, it is entirely possible. Just change the settings according to your liking 对于我们将要改变的汽车模型的阴影设置有两个理由,首先根据非常好的性能方面的实践, 关闭所有游戏对象阴影或接受阴影这个要求不是真的需要。其次,我们觉得车接收阴影并不 能使车看起来更好,它也许会悦目一些,从几何层次上看,阴影不断地在高速行驶下的汽车 上出现和消失,就看你喜欢什么了,如果你想实现更接近现实的影子的行为,这也是完全可 能的,根据自己的喜好仅仅改变设置就可以达到。 (阴影的设置是在 Mesh renderer中的参数上设置的,包括 Cast shadows投射阴影和 Receive shadows接收阴影) The settings we use for the various parts of the car are the following 我们使用的一部分汽车的设置如下: Body: Cast shadows enabled Receive Shadows disabled 车身: Cast Shadows投射能够,Receⅳ ve shadows接收不能够。 Body interior Cast Shadows enabled Receive shadows disabled 车内: Cast shadows投射能够, Receive shadows接收不能够。 Car Windows: Cast and Receive shadows disabled 车窗:Cast和Recε ive shadows投射和接收都不能够。 DiscBrakes: Cast and Receive Shadows disabled 盘式制动器:Cast和Receⅳ ve shadows投射和接收都不能够。(一殷外面也看不到) Wheels: Cast Shadows enabled Receive shadows disabled 车轮: Cast shadows投射能够,Rεcεⅳ ve shadows接收不能够。(车轮要在路面上投射阴 影,车轮一部分是橡胶制的,不反射,一部分是轮毂,佥金属制,但在高速旋转,接收也看不 到 Adding the Car's Components增加汽车的组件 Now let's start adding the components needed to make the car actually work onto the Car Gameobject 现在让我们开始给汽车游戏对象増加需要的组件,以使得汽车能按实际情况工作。 First of all, we need a way to control the car's position in the world by physical simulation, and the built-in rigidBody conponent is perfect for that. with the Car Game Object selected go to the Components menu and select Physics/ Rigid Body. Accept the message Unity gives you about losing prefab connection, and observe how the Gameobject now has a rigidbody attached as one of it's components 首先,我们需要一个方法来控制汽车在物理模拟世界中的位置,并且在其内部构建一个刚体 组什来完善它。选择汽车游戏对象,在 Components菜单下选择 Physics,/ Rigid Boa!y,接 受w比ty给出的失去预制物体连接的信息,并且观察游戏对象现在如何获得一个刚体组件。 The car obviously weighs more than just one kilo, so start by changing the Rigidbody 's ass to something A Rigi Mass 1500 More realistic like 1500 Drag 这款车显然不仅仅只有一公斤重,因此, Angular Drag 0 Use Gravity 廾始通过改变刚体的质量,使得它看起 Is Kinematic Interpolate None 来有500公斤。(Ma单位是K, Freeze rotation 坐标的单位是M) Next we have the drag and angularDrag properties, which are forces that slow down the rigidbody 's speed and rotation. we will control the drag of the car through scripting, so just set the drag and angularDrag properties to o 下一步我们设置rag摩擦力和 angularDrag角摩擦力属性,它们可以强迫刚体的速度 和旋转变慢,我们将通过脚木控制汽车的摩擦力,所以只把aag和 angularDrag属性值 设为O Locate the Car js script in the folder 'scripts/ JavaScripts'and drag it onto the Car Gameobject. This script is the Frun wheel Size 2 engine" of the car, and is the Element 0 A Disc BrakeFL Transform) 上 ement⊥ A DiscBrakeFR(Transtorm Rear wheels script we will focus on explaining Size 2 Element 0 DiscBrakeRL(Transform Element 1 A DiscBrakeRR (Transform 比 most at the end of I op speed tutorial. 在 scripts/ Javascripts’目录下查找 Car s脚本,并且拖动它到汽车游戏对象上,这个 木是汽车游戏对象的“引擎”,并且是脚本中,在这木教程中我们将着重解释比较底层中的 大多数。 The Car-script component has a lot of different variables that will be explained when we start tweaking the car, and even ore when we walk through the code For now we just want to setup what is needed to be able to take the car for a quick test run 当我们开始调整汽车吋,汽车脚本组件中有许多不同的变量将被解释,并且当我们编写代码 时解释的甚至更多,现在我们只想设置必须的,以使我们能够快速的测试运行汽车。 First of all, the car script needs to know about the wheels that the car hasIn the inspector you will see the Front wheels and the Rear Wheels, and notice that both of them can be expanded by clicking on the small arrow to the left of the names 首先,汽车脚本需要了解汽车的车轮。在检查视窗中你将看到 Front Whee/s前轮和Rea Wheels后轮,并且注意到,他们都可以通过名字左边的小箭头点击展开 Set the size of the front and Rear wheels to 2, waking room for two front wheels and two rear wheels 设置前轮和后轮的对象的数组维数为2,使得汽车有两个前轮和后轮。 Now expand the WheelFL, wheelFR, wheelrl and WheelRR in the inspector

...展开详情
试读 20P unity开发赛车游戏中文教程之一
立即下载 低至0.43元/次 身份认证VIP会员低至7折
一个资源只可评论一次,评论内容不能少于5个字
bu淡定 在哪里下载资源啊 完全不知道是那个资源,但是看起来倒是不错 很详细
2014-09-23
回复
unity3dbug 对我们新手有点难
2014-06-08
回复
tiger5680 非常犀利,可惜没有说明文档,对于新人来说有难度啊
2014-03-28
回复
我要改名叫嘟嘟 整体感觉还不错!有那种可以的效果。
2013-07-02
回复
  • 分享宗师

    成功上传21个资源即可获取
关注 私信 TA的资源
上传资源赚积分or赚钱
最新推荐
unity开发赛车游戏中文教程之一 50积分/C币 立即下载
1/20
unity开发赛车游戏中文教程之一第1页
unity开发赛车游戏中文教程之一第2页
unity开发赛车游戏中文教程之一第3页
unity开发赛车游戏中文教程之一第4页

试读结束, 可继续读2页

50积分/C币 立即下载 >