Unity3d_FPS游戏教程3.doc
《Unity3d_FPS游戏教程3.doc》由会员分享,可在线阅读,更多相关《Unity3d_FPS游戏教程3.doc(12页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、【精品文档】如有侵权,请联系网站删除,仅供学习与交流Unity3d_FPS游戏教程3.精品文档.FPS游戏教程3Part 3: Advanced FPS 第三部分 高级FPSThis advancedlevel tutorial extends upon the previous FPS tutorials by introducing game elements such as waypoints, enemy AI, ragdolls and animation.这个高级教程是原先FPS教程的延伸,介绍游戏元素,例如路径点、敌人,布偶和动画。Prerequisites 先决条件This t
2、utorial assumes that you are familiar with the Unity interface and basic scriptingconcepts. Additionally, you should already be familiar with the concepts discussed inPart 1 and 2 of the FPS tutorial series.这个指南已经默认了你已经熟悉了Unity界面和基本的脚本概念。你已经熟悉了第一部分和第二部分的FPS概念的讨论。Setting up设置Were going to build upon
3、the previous FPS tutorial, so well begin by opening that:我们将延伸我们的FPS教程,让我们开始吧: Open the previous project (FPS Tutorial 2).打开原先的项目(FPS 教程 2)Waypoints 路径点This section will introduce waypoints to our game, these are used to inform the robotsof the path that they can walk around. Lets add three waypoint
4、s to our game:这一节将介绍路径点到我们游戏中,即告知机器人它们能够在周围巡逻的路径,让我们增加三个路径点到我们游戏中:Create an empty game object and rename this to Waypoint. Make sure the game object is placed approximately one meter above the ground level.建立一个空的游戏对象并且重命名它为路径点(Waypoint),确保游戏对象被定位在地面上大约一米左右。Add AutoWayPoint script to Waypoint. Notice
5、 how the empty game object now displays a W in the Scene View.给路径点增加一个自动路径点(AutoWayPoint)脚本,注意怎么在场景视窗中显示空游戏对象(按W键)Duplicate the WayPoint game object twice and arrange the waypoints in a triangleshape (position quite far apart).重复制作两个路径点游戏对象并且把它们排成一个三角形(距离远一些)Check that the waypoints are visible to e
6、ach other by firstly clicking on any waypoint then selecting Update Waypoint from the context menu of the AutoWayPoint script (the rightmost button on the component in the Inspector View). A green line will be drawn between visible waypoints, a red line for those which dont have a clear line of sigh
7、t.检查一下这些路径点应该是彼此可见的,首先单击任一个路径点然后在自动路径点(AutoWayPoint)脚本的关联菜单上选择更新路径点(在检查视窗的组件上的最右边按钮),一个绿色的线将在可见的路径点之间画出来,一个红色的线表示视野中没有清晰的线。We have now described the path that an enemy can walk around, now lets add an opponent to the scene.我们现在说明的是一个敌人的巡逻路线,现在让我们在场景中增加一个敌人。Robot AI 机器人人工智能This section will add an en
8、emy robot to our scene.这一节将增加一个敌人在我们的场景中。Select Robot Artwork/robot and drag it into the Scene View making sure all of the robot is above the ground.在Artwork/robot目录下选择机器人(Robot)并且拖拽它到场景中,确保所有的而机器人都在地面之上。Lets give the robot some behavior.让我们给出机器人的一些行为。Add WeaponsScripts/AI to robot. In the AI script
9、 section or robot, assign the FPScontroller as the target (so the robot knows who to hunt down).增加一个WeaponsScripts/AI脚本给机器人。在AI脚本部分或机器人,都要将FPS控制器作为目标(所以机器人才能知道猎捕谁)Add the AIAnimation script to the robot. This controls the animation of our robot (when to run, when to aim etc). This communicates with
10、the AI script to find out what the AI script is currently doing, e.g. are we running, shooting etc.It then crossfades the animations to provide a smooth transition.增加一个AIAnimation脚本给机器人,这些会控制我们机器人的动画(什么时候跑,什么时候瞄准等等)。与人工智能进行交流,找出AI脚本当前应该做什么,例如,我们正在跑,射击等。然后他排演一个动画以提供一个平滑过渡。Now we need to make the robo
11、t controller object a little larger so that he doesnt intersect with the ground. This is because the character controller which is used to prevent the enemy from moving through walls is using a capsule to represent the AI. We need to make this capsule a little larger to match the actual graphics, th
12、is way he will not intersect with the ground anymore.现在我们需要建造一个机器人控制器对象,稍大一点,以便它不会和地面相交。这时因为胶囊代表的人工智能使用的特性控制器(character controller)会阻止敌人穿墙移动。我们需要制造稍大一点的胶囊以匹配实际的图像,这样他不会再与地面相交。Select the robot, then in the Inspector View modify the height and radius valuesof the Character Controller component so that
13、 it encloses the robot. Press playto make sure it works correctly.选择机器人,然后再检查视窗中编辑特性控制器组件的高度和半径值以便它能包住机器人。按运行按钮确保它工作正确。Try making the height and radius values smaller and larger to see the difference.试着将高度和半径值改的稍大一些看看有什么不同。Now we need to give the robot the ability to fire his gun. The robot is conti
14、nuously moving and animating. When he shoots his gun we play an animation on the hands and the graphical gun then spawn the rocket from transform relative to the robot. This transform does not animate, it is simply placed approximately at the point where the gun will be when the shoot animation fire
15、s the rocket.现在我们需要给机器人的枪开火的能力。该机器人在不断移动和动画(用动画表现其反应),当拍摄它手上的枪时我们播放一个动画和枪的图形然后相对于机器人变形衍生出火箭。这个transform不能做成动画,它很简单地大约放置在枪将发射火箭弹的动画的那个点。Create an empty game object and make it a child of the robot (use the hierarchy view).建立一个空的游戏对象并且确保它是机器人对象的子对象(使用层次视窗)Rename the game object gun_spawn.重命名游戏对象为gun_s
16、pawnNow we need to place it properly. In the transform inspector select Reset from the context menu, then move it forward in the z-axis.现在我们需要配置它的属性。在关联菜单上的transform检查器中选择Reset,然后沿Z轴移动它。Add the rocket launcher script to the gun_spawn game object. Assign the rocket prefab to the projectile variable.增
17、加rocket launcher脚本到gun_spawn游戏对象上,分配火箭预制物体到projectile变量上。Make a prefab of this robot, call it Robot. This will allow you to create more enemies easily.制造一个机器人预制物体,调用它,这将允许你建立更多的敌人。Play the game and check that the robot fires at you.运行游戏并且检查那个朝你开火的机器人。Although you can shoot the robot, it is not confi
18、gured to take damage, well remedythis in the next section.尽管你能朝机器人射击,但它没有配置获得伤害,在下一节中我们将补救这些。Robot Damage 机器人伤害Attach the CharacterDamage script to the Robot prefab.附着CharacterDamage脚本到机器人预制物体上。Play the game, shoot the robot with the machine gun and he should disappear.运行游戏,用机枪朝机器人射击并且它会消失。Ragdolls
19、布偶Ragdolls emulate a natural skeletal bone structure, this will allow our robot to fall naturally when killed. This section will show how to setup a ragdoll.布偶模仿一个天然的骨骼结构,这些将允许我们的机器人在被杀死时自然跌倒,这一节将显示如何设置一个布偶。Firstly, create a new scene (File New Scene). Were going to setup our ragdoll in here. Save y
20、our current scene if necessary.首先,建立一个新的场景(File New Scene)。我们将在这装配我们的布偶,如果需要保存你当前的场景。Create a cube (resize if necessary), this will be used as a platform for our robot. Drag in the robot to the Scene View so that it is positioned above the cube.建立一个cube(如果需要就重定义一下尺寸),这将被用作我们的机器人的平台,拖拽机器人到场景视窗中以便它被定位
21、到cube之上。Remove the animation component. This is important otherwise the animations will interfere with the physics.删除动画组件,这一点很重要,否则动画在物理上将被干扰。Now use the ragdoll wizard: Game object Create Other Ragdoll. 现在使用布偶向导:Game object Create Other RagdollA dialog box appears, now we have to assign all the bon
22、es to the correct slots in the wizard. We assign the bones by dragging the values from the Robot in the Hierarchy View onto the correct place in the dialog box. Expand the Robot gameobject in the Hierarchy View if necessary to reveal this.出现一个对话框,现在我们必须在向导的正确插槽中指定所有的骨头,我们通过拖拽层次面板上的值分配机器人的骨头到对话框中正确的地
23、方,如果需要在层次视窗中扩大机器人游戏对象以显露出它。Firstly, rootHandle (Hierarchy View) maps onto root (in the dialog box). Drag rootHandle onto the placeholder beside root in the dialog box.首先,rootHandle(层次视窗)映射到root(在对话框中),拖拽rootHandle到对话框的root旁边的定位手柄处。Set Total Mass to 4设置总质量为4Legs 腿Assign upleg_L to Left Hip.分配左大腿(uple
24、g_L)到Left Hip。Assign lowleg_L goes to Left Knee.分配左小腿(lowleg_L)到Left KneeAssign heel_L goes to Left Foot.分配左脚踝(heel_L)到Left FootRepeat for the right leg.重复分配右腿Upper body / Arms 上半身和胳膊Assign upArm_L goes to Left Arm.分配左手(upArm_L)到Left ArmAssign elbow_L goes to Left Elbow.分配左肘(elbow_L)到Left ElbowRepea
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Unity3d_FPS 游戏 教程
限制150内