The book "Unity and C #. Gamedev from idea to implementation. 2nd ed

    imageHi, habrozhiteli!

    Jeremy Gibson Bond, conceived this book, set a simple goal: to introduce you to all the tools and transfer the basic knowledge necessary to achieve success in the development of games and prototypes. The author tried to squeeze the maximum amount of knowledge into this book. Unlike many other books, this one combines both disciplines - game design and digital development (i.e. computer programming) - and wraps them with iterative prototyping practice. The advent of advanced and relatively easy to use game engines, such as Unity, has further simplified the creation of prototypes expressing the concepts of game design and increased your chances of becoming a qualified (and sought-after) game designer.

    The book is divided into four parts
    Part I. Designing the game and prototyping on paper


    The first part of the book begins with a study of various game design theories and the analytic foundations of game design, as suggested in some earlier books. This section describes the Layered Tetrad, a way of combining and expanding the best features of these earlier theories. A lot of attention has been paid to the study of multi-level notebooks, because it concerns many decisions that you will have to make as a designer of interactive interactions. This part also contains information about interesting problems of various disciplines of game design; describes the process of prototyping on paper, testing and iteration; gives specific information that can help you become one of the best designers; Effective project and time management strategies are presented,

    Part II Digital prototyping


    The second part of the book teaches programming. This part is based on my many years of experience teaching non-technical students how to express game design ideas in digital code. If you have no development or programming experience, this part is for you. But even those with some experience can look over this part to get acquainted with new tricks or to refresh some approaches. The second part covers C # - our programming language - from the very basics to the inheritance of classes and techniques of object-oriented programming.

    Part III. Prototypes of games and examples


    The third part of the book includes several examples, each of which demonstrates the process of developing a prototype of a game of a certain genre. This part has two goals: it reveals some advanced techniques for rapid prototyping of games using my own approach to prototyping as an example and helps form the foundation on which you can create your own games. Many books about Unity (our development environment for games) use a similar approach, but lead the reader through a single, monolithic example over several hundred pages. This book, by contrast, shows some much shorter examples. The end results of these examples are inevitably less reliable than those found in other books, but I am convinced that diversity will help you better prepare for your own projects in the future.

    Part IV Applications


    There are several important applications worth mentioning here in this book. In order not to repeat the same information and not force you to search for it in different chapters, all the information that is repeatedly mentioned in the book or which, it seems to me, you will want to refer to later (when you finish reading the book for the first time) is placed in applications. Appendix A provides a brief step-by-step introduction to creating a game project in Unity. The longest application is Appendix B, Useful Ideas. Despite the unassuming title, I am sure you will most often refer to this application after you read the book for the first time. “Useful ideas” is a collection of advanced techniques and strategies that I myself constantly use when performing prototyping of games, and I think that here you will find a lot of interesting things for yourself. Third and finally, the application - a list of links to resources on the Internet, where you will find answers to questions not covered in this book. It is often difficult to determine the right place to seek help; This application contains links that I myself use most often.

    Excerpt. Using Google Sheets to balance weapons


    Another application of mathematics and programs, such as Google Sheets, in game design is to balance different types of weapons and capabilities. In this section, you will see the weapon balancing process for a game similar to Sega's Valkyria Chronicles. In this game, each weapon has three important characteristics:

    • The number of shots fired simultaneously.
    • The degree of damage caused by each shot.
    • The probability of hitting the target of each fired bullet at a given distance.

    When balancing different types of weapons, the goal is usually to make them approximately equal in power, but at the same time give distinctive features. For example, some weapons may have such distinctive features:

    • Pistol: main weapon; allows you to cope with most situations, but not the best.
    • Rifle: A good choice for hitting targets at medium and long range.
    • Shotgun: a lethal weapon at short range, but its power drops rapidly with increasing distance; has a low rate of fire, so accuracy is of great importance.
    • Sniper rifle: an extremely bad choice for close combat, but a fantastic weapon for long-range shooting.
    • Machine gun: has a high rate of fire, so even with not the highest accuracy it has a high lethal force, thanks to this it seems the most reliable weapon, although not the most powerful.

    In fig. 11.14 shows the values ​​of the characteristics of weapons, which seemed to me successful at first glance. The value of ToHit (For hitting) is the minimum number of points that fell when throwing a hexagonal dice, which means hitting the target at a given distance. For example, for a pistol in cell K3 corresponding to a distance of 7 units, the number 4 is indicated, that is, if a player shoots at a distance of 7 units, it will be considered that he hit the target if the number 4 or more falls on the die. This gives a 50% chance of hitting (because the hit counts if 4, 5, or 6 points are dropped).

    image

    Determining hit probability for each bullet


    In the cells under the heading Percent Chance, we need to calculate the probability of hitting each target fired from a given weapon at a given distance. To do this, follow these steps.

    1. Create a new document in Google Sheets and enter all the data as shown in fig. 11.14. To change the background color of the cells, use the Cell Color button in the cell formatting tools (Fig. 11.2).

    Judging by the value in cell E3, a shot from a pistol at a distance of 1 unit reaches the target if 2 points or more fall out when throwing a die. This means that a miss occurs only when 1 point is dropped, and when 2, 3, 4, 5, or 6 points are dropped, the shot reaches the target. So, the share of hits is 5/6 (or ≈ 83%), and now we need a formula to calculate it. According to rule 7 of determining probabilities, this corresponds to a miss probability of 1/6 (i.e., the number in ToHit minus 1 and divided by 6).

    2. Select cell P3 and enter the formula = (E3-1) / 6. As a result, cell P3 displays the probability of a miss from the pistol at a distance of 1 unit. Arithmetic operations in Sheets are performed in accordance with the rules of mathematics, so the division will be performed before subtraction, if you do not enclose the expression E3-1 in parentheses.

    3. Again we use rule 7. According to it, 1 - miss probability = probability of defeat, therefore replace the formula in cell P3 with = 1 - ((E3-1) / 6). Now the number 0.8333333 should appear in it.

    4. To convert the decimal fraction in cell P3 to percent, select cell P3 and click on the button with the% symbol in the number formatting toolbar, as shown in Fig. 11.2. You can also click a couple of times on the button to the right of the button with the% symbol (with the inscription .0 and the left arrow). It will remove the decimals, and only 83% will be displayed in the cell instead of the more accurate but confusing% 83.33. In this case, only the displayed value will change - the actual number will remain the same - and the cell will retain accuracy for further calculations.

    5. Copy the formula from cell P3 and paste it into all cells P3: Y7. You will see that all the calculations were completed successfully, with the exception of the empty cells in the ToHit section, for which the percentage of hits is 117%! Change the formula so that it ignores empty cells.

    Select cell P3 again and replace the formula with = IF (E3 = "", "", 1 - ((E3-1) / 6)). The IF function in Sheets has three arguments, separated by commas.

    • E3 = "": argument 1 - condition: is the contents of cell E3 equal to the empty value ""? (i.e. is E3 an empty cell?)
    • "": argument 2 - what to put in the cell if the condition in the first argument is true. That is, if E3 is an empty cell, clear cell P3.
    • 1 - ((E3-1) / 6): argument 3 - what to put in the cell if the condition in the first argument is false. That is, if E3 is not an empty cell, use this formula.

    7. Copy the new formula from cell P3 and paste it into cells P3: Y7. Now the empty cells in the ToHit section will correspond to the empty cells in the Percent Chance section. (For example, L5: N5 are empty cells, so the corresponding W5: Y5 cells will also be empty.)

    8. Next, add a little color to this diagram. Select cells P3: Y7. From the Sheets menu, select Format> Conditional formatting. A new Conditional format rules panel appears on the right side of the window. Conditional formatting allows you to determine the display format of cells depending on their content.

    9. Click the Color scale tab at the top of the Conditional format rules panel.

    10. In the Preview section of the Color scale tab, you will see the word Default in the green gradient image. Click on the word Default and select the option below in the center: Green to yellow to red (From green to red through yellow).

    11. Click on the Done button, and the Percent Chance section will take the form, as in Fig. 11.15.
    image

    Average Damage Calculation


    The next step in the balancing process is to determine the average damage caused by each type of weapon at a certain distance. Since some types of weapons fire several shots at once and each shot does certain damage, the average damage will be equal to the product of the number of shots per the damage of one shot and the probability of each bullet hitting:

    1. Select the O: Z columns and copy them (press Command-C or Ctrl + C on PC or select the menu item Edit> Copy (Edit> Copy)).

    2. Select cell Z1 and paste (Command-V, Ctrl + V on PC or select the menu item Edit> Paste (Edit> Paste)). As a result, additional AA: AK columns will be added to the table and filled with data from the newly copied columns.

    3. Enter the text Average Damage in cell AA1.

    4. Select cell AA3 and enter the formula = IF (P3 = "", "", $ B3 * $ C3 * P3) into it. As in the formula for cell P3, the IF function ensures that calculations will only be performed for non-empty cells. The formula includes absolute references to columns $ B and $ C, because column B stores the number of shots, and column C the damage done by one shot regardless of the distance to the enemy. In this case, only row numbers, but not column numbers, should be shifted during copying (therefore, only columns are described by absolute links).

    5. Select cell AA3 and click on the right-most button in the area with the
    number formatting tools (labeled 123). Select Number
    from the menu that appears.

    6. Copy cell AA3 and paste it into cells AA3: AJ7. Now they will display the exact values, but conditional formatting is still tied to the Percent Chance section, due to which numbers above 1 force percentages in the range from 0 to 100% in the Percent Chance section to appear on green background.

    7. Select cells AA3: AJ7. If the Conditional format rules panel is
    no longer displayed, select Format> Conditional formatting from the main menu to open it again.

    8. With the selected AA3: AJ7 cells, you should see in the Conditional format rules panel a rule with the name Color scale (Gradient) and with links to cells P3: Y7, AA3: AJ7 below it. Click on this rule.

    9. In the opened settings, in the Apply to range section, leave only P3: Y7 and click on the Done button. As a result, the previous design of the Percent Chance section will be restored.

    10. Select cells AA3: AJ7 again. In the Conditional format rules panel, click the Add new rule button.

    11. In the Preview field on the Color scale tab, select the option Green to yellow to red (from green to red through yellow), as before. Then click on the Done button.

    As a result, different formatting rules will be applied to the Percent Chance and Average Damage sections. Separating the rules for different areas guarantees their separate application, which is important because the ranges of numbers in different sections are too different from each other. Now the Average Damage section should look like the one shown in Fig. 11.15.

    Displaying average damage graphs


    The next important step is to plot the average damage graphs. Even though a careful study of the numbers already allows you to draw some conclusions, the graphs supported by Sheets will simplify this work and help you visually evaluate what is happening. To do this, follow these steps.

    1. Select cells A2: A7.

    2. Scroll the page so that you can see the Average Damage section. With A2: A7 cells still selected, hold down the Command key (or Ctrl on PC), left-click on cell AA2 and, while holding down the mouse button and mouse button, move the pointer to cell AJ7 to select the area AA2: AJ7. You should now have two areas selected: A2: A7 and AA2: AJ7.

    3. Click on the chart button (see Figure 11.2) to open the chart editor.

    4. Click on the Chart type drop-down list (the type of chart in which the text “Column chart” is displayed, see Figure 11.6A) and select the leftmost type in the Line section - this is the upper left pictogram with blue and red broken lines.

    5. At the bottom of the DATA tab, select the Switch rows / columns check box.

    6. Select the Use column A as headers check box. Also make sure that the Use row 2 as labels check box is selected.

    7. Click the close button on the Chart editor panel to complete the creation of charts.

    As a result, you get a diagram like in Fig. 11.16. As you can see, not everything is smooth with weapons. Some species, such as the Sniper Rifle and Shotgun, have pronounced distinctive features, as we hoped (the shotgun has great lethal force at close range, and the sniper
    image

    rifle is better suited for hitting targets at long range), but among others, problems are clearly observed:

    • The machine gun (Machine gun) was ridiculously weak.
    • The pistol (Pistol) turned out, perhaps, excessively powerful.
    • The rifle (Rifle) also turned out to be too powerful against the background of other types of weapons.

    Simply put, different types of weapons are poorly balanced among themselves.

    Duplicate weapon parameters


    In the process of balancing weapons, it is convenient to have information before and after balancing:

    1. First, move the chart down, below line 16.

    2. Double-click within the chart, and then the Chart editor panel will open. Select the CUSTOMIZE tab in the upper part of the panel (Fig. 11.6D). Open the Chart axis & titles section (Chart and axis names, Fig. 11.6E) and enter the Original text in the Title field (Original balance, Fig. 11.6F).

    3. Now you need to copy the already added data and formulas. Select cells A1: AK8 and copy them.

    4. Click in cell A9 and paste. As a result, new cells A9 should appear: AK16 - a complete copy of all previously created data.

    5. Replace the text in cell A10 with Rebalanced. In this set, we will make changes and try new values.

    6. To create a diagram based on the new data that is identical to the one that displays the source data, select the cell ranges A10: A15, AA10: AJ15, exactly as you selected cells A2: A7, AA2: AJ7 in steps 1 and 2 in the " Displaying average damage graphs. ” Follow the instructions in that section and create a second chart that displays balanced values.

    7. Position the new chart to the right of the previous one so that you can see both charts and the data above them.

    8. Replace the name of the new chart with Rebalanced (After balancing).

    Total Damage Display


    Add one more statistic, which is also useful to see - total damage. This is the sum of the average damage done by the weapon in all ranges, which will allow you to get an idea of ​​the total power of the weapon. To do this, you can use the trick, which I often use to create simple histograms inside cells in a spreadsheet (that is, not as separate diagrams). The result is shown in fig. 11.17.

    1. Right-click on the column header AK and select Insert 1 right from the menu that appears.

    2. Right-click on the heading of column B and select Copy. As a result, the entire column B will be copied to the clipboard.

    3. Right-click on the AL column heading and select Paste. As a result, the contents of column B, including background and font, will be inserted into the AL column.

    4. Right-click on the AL column heading and select Insert 1 right.

    5. In cell AL1 and AL9, enter the text Overall Damage.

    6. Select cell AL3 and enter the formula = SUM (AA3: AJ3). It calculates the average damage done by the gun in all ranges (it should be equal to 45.33).

    7. To perform the histogram trick, you need to convert this real number to an integer, that is, the result of the SUM function needs to be rounded. Replace the formula in AL3 with: = ROUND (SUM (AA3: AJ3)). Now the cell should display the number 45.00. To remove extra zeros, select cell AL3 and click on the button to delete decimals, as you did before (the third button in number formatting tools).

    8. Select cell AM3 and enter the formula = REPT ("|", AL3). The REPT function repeats the text in the first argument a specified number of times in the second argument. In this case, the text is a vertical bar symbol (to enter it, you need to press the Shift key and, while holding it, press the backslash key (\), which is located above the Return / Enter key on most keyboards), and it will be repeated 45 times, because cell AL3 contains a value of 45. A small column appears in cell AM3, extending to the right. Double-click on the right border in the AM column heading to expand it to the desired width.

    9. Select cells AL3: AM3 and copy them. Paste the contents of the clipboard into cells AL3: AM7 and AL11: AM15. Now you will have a text histogram before your eyes, showing the total damage of all types of weapons, the original and after balancing. Finally, adjust the AM column width again to see all the vertical bar characters.

    Weapon balancing


    Now we have two data sets and two diagrams, and you can try to balance the weapon. How to increase the power of a machine gun? What should be increased - the number of shots, the probability of hitting the target, or the lethal force of one shot? When balancing, some additional rules of the game should be considered.

    • In this example of the game, the characters have only 6 health units, so they lose consciousness when inflicted damage equal to 6 units.
    • In Valkyria Chronicles, if the enemy was not killed by an attacking soldier, he automatically goes on a counterattack. Therefore, dealing damage in 6 units is preferable to dealing damage in 5 units, as this also protects the attacker from a counterattack.
    • A weapon with a large number of shots (for example, a machine gun) gives a higher probability of causing average damage in one turn, while a weapon with a single shot (for example, a shotgun and a sniper rifle) seems less reliable. In fig. 11.7 shows how the probability distribution shifts more and more toward the average with an increase in the number of dice tossed to determine the probability of hitting the target with multiple shots.
    • Even with all the information available, this diagram does not reflect some aspects of the balance of weapons, including the remark about a higher probability of inflicting the average damage done above on a weapon with several shots, as well as the advantage of a sniper rifle for hitting enemies too far for effective counterattack.

    Try to balance these weapons parameters yourself, changing only the values ​​in cells B11: N15. Do not touch the initial parameters and do not change anything in the sections Percent Chance (Percentage of probability) and Average Damage (Average damage); both of them, like the Rebalanced diagram (after balancing), will be updated automatically and reflect the changes you made in the Shots, D / Shot and ToHit cells. After playing with the numbers, keep reading.

    One example of balanced values


    In fig. 11.17 you can see the parameters of the weapons that I picked up for the designed prototype. Of course, this is not the only way to balance weapons, and not even the best, but it allows you to achieve many design goals.

    • Each weapon has its own distinctive characteristics, and none of them is excessive or insufficiently powerful.
    • Even though the shotgun (Shotgun) may seem very similar to a machine gun in this diagram, these two types of weapons differ significantly in two factors: 1) a hit with 6-point damage from the shotgun immediately puts the enemy out of action; and 2) the machine gun fires a lot of bullets, so it will do average damage much more often.
    • The gun has decent characteristics for close range and is more versatile than a shotgun or machine gun due to its ability to hit enemies at longer distances.

    image

    • The rifle (Rifle) really shines at medium distances.
    • A sniper rifle is no good at close range, but is the best weapon at long range. A hit from a sniper rifle deals 6 points of damage like a shotgun, that is, it is also capable of destroying the enemy with one shot.

    Despite the fact that such balancing using a spreadsheet does not cover all the possible consequences of weapon design, it still remains an important tool in the designer's arsenal, because it helps to quickly analyze large amounts of data. Some free game designers spend most of their time adjusting data in spreadsheets, trying to make their games a little more balanced, so if you are going to work in the field of game design, ownership of spreadsheets and data-based design (which we just did) you very useful.

    Positive and negative feedback


    One of the last key elements of the game balance support that we will discuss is the concept of positive and negative feedback. In a game with positive feedback, the player who has taken the lead from the very beginning receives an additional advantage and is likely to win. In a game with negative feedback, losing players gain an advantage.

    Poker is a great example of a positive feedback game. If a player wins a big pot and has more money than other players, individual bets mean less to him and he has more freedom to take steps such as bluffing (because he can afford to lose something). On the contrary, the player who lost money at the beginning of the game has less freedom of action and no chance to take risks. There is a strong positive feedback in the Monopoly game, where the player with the best objects constantly receives more money and is able to force other players to sell their objects if they are unable to pay the rent when they get to their sites. For most games, positive feedback is an undesirable occurrence, but it is well-suited for cases where it’s required, so that the game ends quickly (although Monopoly does not use this advantage because the designer of this game wanted to show the misfortunes of the poor in a capitalist society). Single player games also often have positive feedback mechanisms, the purpose of which is to make the player feel omnipotent in the game.

    Mario Kart is a great example of a negative feedback game in the form of random items awarded to a player when they hit boxes. Usually a player gets a banana (essentially a defense weapon), a bunch of three bananas or a green shell (one of the weakest weapons). The player in the last place often receives more powerful items, such as lightning, which slows down all other players involved in the race. Negative feedback makes games more fair to players who have not managed to break into the lead and longer, and also gives all players the opportunity to feel that they still have a chance to win, even if they are far behind.

    Summary


    There was a lot of math in this chapter, but I hope you made sure that knowing it is very useful to you as a game designer. Most of the topics covered in this chapter deserve a separate book, so I encourage you to continue to study them if you are interested.

    »More information about the book can be found on the publisher’s website
    » Contents
    » Excerpt

    For Khabrozhiteley 20% discount on the coupon - Unity

    Upon payment of the paper version of the book, an electronic version of the book is sent by e-mail.

    Also popular now: