Abstract
Video games come in many varieties: aim-and-shoot games, city-building games, racing games... the list goes on. In many, you get points for colliding with or hitting something. In this computer and video games project, you will learn about how hit boxes are used to detect collisions and you will determine if the size and placement of a hit box affects the score in the game.Summary
Michelle Maranowski, PhD, Science Buddies
Objective
To build a video game using a programming language of your choice and experiment with how the size and placement of a hit box affect the game's score.Introduction
If, on my daily walk, I bumped into my neighbor walking her dog, we would both know the reason we bumped into each other was that we were trying to occupy the same space at the same time. But how does a video game "know" when two characters have bumped into each other, or if a racing car has hit the speedway's wall? The answer is through collision detection and hit boxes. Why are hit boxes important? Because a poorly designed hit box can lead to errors during game play, like a collision between two characters in a game that are visually far apart. It is also frustrating for a player who can't score in a game.
A hit box, also known as a bounding box or bounding volume, is either a two-dimensional or three-dimensional shape that surrounds a character, which the game's programming uses to detect a hit or collision. Figure 1 shows an example of a hit box or bounding box. In the case of the racing game mentioned, both the racing car and the speedway wall have a hit box surrounding them. If the x- and y-coordinates of the racing car's hit box overlap or match the x- and y-coordinates of the wall's hit box, then the game's programming registers a collision. As the character moves through the game, the size, shape, and coordinates of the hit box change. If the character is still, the hit box lies on top of the character. But as a character runs or moves, the hit box stays marginally behind it in order to account for lag. Lag is the delay between the action of the player and the reaction of the game's programming (or the server if the game is online). This makes a big difference in shooting games, when the player can shoot accurately at a character but doesn't score because the character has moved. To compensate for lag, the hit box trails spatially behind the character.
Figure 1. In this image, a bust of Athena is surrounded by a hit box or bounding box. (Wikipedia, 2011)
A hit box can be a simple rectangle that envelops the entire character, several boxes that surround the character's head, torso, or arms, or a complicated set of boxes or cylinders that closely follows the character's outline. A basic rectangular box means that the calculations that the game's programming performs to determine if a collision has occurred are simple. A complicated set of hit boxes or cylinders leads to complicated and time-consuming calculations. But the advantage that a complicated scheme of hit boxes has over a simple rectangle is that the collision is more realistic for the players.
In this computer and video game project, you will experiment with hit boxes and investigate how the size and placement of the hit box affects game score. You will use a programming language of your choice to perform your experiment. You will use the engineering design process to build a simple video game that enables you to test the effect of varying the dimensions of the hit box.
Terms and Concepts
- Hit box
- Programming
- Lag
- Flowchart
- Sprite
Questions
- What types of video games involve collision detection? Can you give specific examples of ones that do and do not?
- Play a video game that involves collision detection. How do the hit boxes change over the time it takes to play the game?
- What are some common types of hit boxes?
Bibliography
- Valve Developer Community Wiki Contributors (2012, June 27). Hitbox. Valve Developer Community. Retrieved January 3, 2018.
- # Link Name="Games_p028.2" Value="HtmlAnchor" HtmlText="EventHubs.com" #]. (2009, September 21). Guide to understanding hit boxes in Street Fighter. Retrieved August 31, 2011.
This page will help you get started with a programming language you can use to make a video game:
- Science Buddies staff. (2017). Kid-friendly Programming Languages and Resources. Retrieved January 3, 2018.
Materials and Equipment
- Computer with internet connection
- Programming language of your choice. See the Kid-Friendly Programming Languages and Resources for ideas.
- Volunteer game players (10). Try to find game players who are all approximately the same age.
- Lab notebook
Experimental Procedure
Working with Human Test Subjects
There are special considerations when designing an experiment involving human subjects. Fairs affiliated with Regeneron International Science and Engineering Fair (ISEF) often require an Informed Consent Form (permission sheet) for every participant who is questioned. Consult the rules and regulations of the science fair that you are entering, prior to performing experiments or surveys. Please refer to the Science Buddies documents Projects Involving Human Subjects and Scientific Review Committee for additional important requirements. If you are working with minors, you must get advance permission from the children's parents or guardians (and teachers if you are performing the test while they are in school) to make sure that it is all right for the children to participate in the science fair project. Here are suggested guidelines for obtaining permission for working with minors:
- Write a clear description of your science fair project, what you are studying, and what you hope to learn. Include how the child will be tested. Include a paragraph where you get a parent's or guardian's and/or teacher's signature.
- Print out as many copies as you need for each child you will be surveying.
- Pass out the permission sheet to the children or to the teachers of the children to give to the parents. You must have permission for all the children in order to be able to use them as test subjects.
Programming the Test Game
- First you need to decide what programming language you will use to make your game. The Kid-Friendly Programming Languages and Resources page has lots of suggestions. However, to do this project you will need to make sure you pick a language that allows you to modify or control hit boxes. For example, many two-dimensional games use images called sprites to represent characters and objects in the game. The hit box can be a simple shape, like a circle or a square, that surrounds the entire object, a more complicated shape that closely follows the object's outline, or a combination of multiple smaller shapes. Try searching online for "[your programming language] hit box" or "[your programming language] sprite collisions" to learn more. If you aren't sure what language to use, GameMaker is a good starting point because it has options that let you easily adjust the hit box for a sprite.
- Before you start your project, work through some tutorials for the programming language you chose, and make sure you are comfortable using it.
- After practicing, it is time to start the project. In order to test your hit boxes, build a simple test game where one object collides with another several times. An example of a test game could be where you scatter an object several places in a room, and the goal is for the player to gather as many of the objects as possible in a set time. Another could be using a hook to "catch" as many fish as possible from the ocean in 10 seconds. In this example, both the hook and fish are sprites as described in the tutorials and the ocean is a room that you build.
- Follow the engineering design process to build your simple program. The following list will help you to focus your efforts. Remember, if you need assistance or are troubleshooting, the website for your programming language will probably contain tutorials, help information, and forums where you can ask questions.
- Define the problem. In this case, you will create a simple test game for the purpose of testing various hit boxes. Refer to the Science Buddies define the problem page to help you set the boundaries for the game.
- Do background research. Play some other video games and figure out techniques from these games that you can use in your own.
- Develop the project requirements. In this case, you are building a video game that helps you test the effects of differently sized hit boxes. Refer to the Science Buddies design requirements section to get tips on how to formulate your game's design requirements. Here are some ideas to consider:
- What kind of game should you build? The game should be engaging for the player.
- What kinds of sprites will you use and where will you get them?
- You need sprites that are big enough to easily change the size and position of the hit box.
- How will you control the time the player has to finish the game—with a timer incorporated in the game's programming or an outside timer that you control?
- How will you count the player's score?
- Create and analyze solutions. Keeping your project requirements in mind, think about different ways that you could build your game. Take a look at the Science Buddies document on creating alternative solutions to guide your efforts. Once you have developed a few solutions, analyze the solutions by making rough sketches and flowcharts for each one. Refer to the Science Buddies best solution document to help you pick a working solution.
- Build and test a sample video game. Once you have created a set of requirements and a possible solution, it is time to open your programming environment and start working on building a sample video game. Remember to review your requirements to keep focused on the task. Review the Science Buddies prototyping document.
- Program your video game. Keep testing each step of the game as you work. When you have fulfilled a requirement or task, run the game and test that requirement or task out.
- Break the game programming down into smaller tasks so that the project is not overwhelming.
- Fix small issues as they come up. This will prevent your having a long set of events at the end that don't work.
- Once you have finished programming your game, check to see that all of the project requirements are fulfilled.
- Test the game. Review the Science Buddies test and redesign document to help organize your work.
Hit Box Testing
- Now that your video game is built, it is time to start testing the effect of varying the size and position of the hit boxes.
- Based on the game example given where the player is supposed to gather fish using a hook, there are many ways to explore the effect of hit box sizes. You will use the game score as a way to explore the effect of changing the hit boxes. The following procedure will give just one example (changing the hit box size of the fish), but you could also change the hit box size of the hook.
- Before changing the hit box, direct each one of your players to play the game for the set time with all the default hit box sizes in place. Record each player's score in your lab notebook in a table like the one shown.
Player | Score | ||
---|---|---|---|
Smaller Hit Box | Default Hit Box Size | Larger Hit Box | |
- Now change the size of the hit box for the fish to make it larger. Remember that you will need to look up how to do this in your programming language. Save the changes.
- Ask the first player to come in, sit down, and play the game. After the set time is over, record the player's score in your lab notebook.
- Repeat step 5 for the additional players. Record all scores in your lab notebook.
- Repeat steps 4 through 6, but this time make the hit box smaller.
Analyzing Your Data
- Plot the data you gathered in the previous section on a scatter plot. Label the x-axis Hit box size and the y-axis Score. Mark a point for each player's score. You can also calculate an average score for each hit box size and add a trend line to your graph.
- Based on your graph, does varying the hit box affect the score? Which condition affects the score the most?
Ask an Expert
Variations
- Some programming environments are easier than others in which to create certain game features. Try programming your video game in both GameMaker and Scratch (or another programming environment of your choice from the table of the Science Buddies resource Kid-Friendly Programming Languages and Resources. How do the two programs compare? Which programming environment made it easier to create hit boxes in? Why?
- Some video games use visual effects to help a player know when they have, or have not, successfully come in contact with a hit box. What are some examples of such visual feedback in the games you play? Can you create and apply helpful visual effects for the hit boxes in your game?
Careers
If you like this project, you might enjoy exploring these related careers: