下面我们让汽车动起来。为对象car body创建脚本car body Script,为了操控车子加入模块Building Blocks/Controller/Keyboard/Switch on Key,将模块On端与Start链接,点击鼠标右键选择Cons***ct->Add Behavior Output 0加入一个输出端,多次点击直到模块具有6个输出端。
下面为车子加入一个跟随的第三视角,新建一个摄影机命名为Follow Camera,将其Perspective设为Custom,Field of View设为50,并将其放置在车子的后上方。
建立脚本Follow Camera Script,拖入模块Building Blocks/Cameras/Montage/Set As Active Camera和Building Blocks/3D Transformations/Constraint/Look At,将Set As Active Camera模块的In端与Start链接,使得运行时初始的默认摄像机为Follow Camera。将Set As Active Camera模块的Out端与Look At模块的In端链接,Look At模块的参数Referential设为car body,从而将Follow Camera的拍摄目标设为车身。为了使摄像机随着拍摄目标的移动而旋转,将Look At模块的Out端与In端链接,形成循环。
此时摄像机只能旋转,为了使其始终与车子保持一定距离跟随车子移动,载入模块Building Blocks/3D Transformations/Constraint/Keep At Constant Distance,双击设置参数,Position中的Y设为8,使得摄像机镜头距水平面的竖直距离为8,Referential值设为car body,与车子保持的距离Distance设为15。
接下来为了使视角能够在Follow Camera与Inside Camera之间进行切换拖入两个Building Blocks/Cameras/Montage/Set As Active Camera模块和两个Building Blocks/Controller/Keyboard/Key Event模块,如图连接起来,将两个Key Event模块的Key Waited参数设为Enter,第一个Set As Active Camera模块的Target参数设为Inside Camera,第二个Set As Active Camera模块的Target参数设为Follow Camera。由此运行时,按下Enter键,视角将在Inside Camera和Follow Camera间切换。