官术网_书友最值得收藏!

The player's tank

Before writing the script for our player's tank, let's take a look at how we set up the PlayerTank game object. Our Tank object is a simple Mesh with the Rigidbody and Box Collider components. The Tank object is composed of two separate meshes, Tank and Turret, such that Turret is a child of Tank. This structure allows for the independent rotation of the Turret object using the mouse movement and, at the same time, will follow automatically the Tank body wherever it goes. Then, we create an empty game object for our SpawnPoint transform. We use it as a reference position point when shooting a bullet. Finally, for the player's Tank, we need to assign the Player tag to our Tank object. Now let's take a look at the controller class:

Our tank entity

The player's Tank is controlled by the PlayerTankController class. We are using the W, A, S, and D keys to move and steer the tank, and the left mouse button to aim and shoot from the Turret object.

In this book, we assume the use of a QWERTY keyboard, as well as the use of a two-button mouse, with the left mouse button set to the primary mouse button. For those readers who use a different keyboard, all you have to do is pretend that you are using a QWERTY keyboard or try to modify the code to adapt it to your keyboard layout. It is pretty easy!
主站蜘蛛池模板: 赞皇县| 广东省| 苍山县| 迁安市| 武穴市| 葫芦岛市| 教育| 茶陵县| 手游| 仙桃市| 格尔木市| 鱼台县| 安泽县| 汕头市| 晋州市| 红河县| 松溪县| 杂多县| 徐汇区| 益阳市| 长顺县| 宁蒗| 大连市| 海林市| 凌源市| 进贤县| 集安市| 双江| 达孜县| 罗江县| 广宁县| 曲周县| 潼关县| 周至县| 九龙坡区| 辉县市| 鹤壁市| 兴隆县| 鲁甸县| 汝南县| 呼和浩特市|