## Addition of Vectors in Computer Games

Most likely, you’ve either played computer games before or play them regularly. Whatever your favorite game may be, it’s highly probable that various objects within the game, such as cars, warriors, or balls, are animated using vectors and vector addition. Let’s take a closer look at how this happens.

### Adding Vectors Using Parallelogram Law in a 2D Tennis Game

#### Vector Describing the Ball Velocity

Imagine a simple 2D computer game where a tennis player strikes the ball:

Vectors, commonly studied in high school, are a perfect way to describe and predict how the tennis ball will move. Let’s see.

When the player strikes the ball, it has its initial velocity, let’s say, 90 feet per second. Therefore, it can be described by a vector \(\vec{b}\) with a magnitude of 90 feet per second and a direction of 90 degrees. This can be visualized in the animation below.

#### Making Game More Realistic by Adding a Vector for Wind

What if a game developer wants to make the game more realistic? In the real world, when people play tennis, wind impacts the trajectory of the ball. How can we incorporate wind into a computer game? The answer is simple – by introducing a vector that describes the wind and then adding it to the vector that describes the ball’s velocity. Let’s see how it works.

Suppose we have a strong North-East wind that displaces the direction of the ball by approximately 0.71 foot each second. The animation below demonstrates how the wind can be modeled using a vector (the wind vector is represented in blue).

So, how do we predict the trajectory of the ball when it’s impacted by the wind?

#### Adding the Ball Velocity Vector and the Wind Vector Using Parallelogram Law

Take a look at the animation below. It illustrates how the vectors of the ball velocity and wind are extended by two additional sides to form a parallelogram. Subsequently, the resultant vector is drawn from the origin (0,0) to the opposite corner of the parallelogram.

Let’s check it carefully:

The coordinates of the ball velocity vector \(\vec{b}\) are ⟨0,90⟩, and the coordinates of the wind vector \(\vec{w}\) are ⟨-0.5, -0.5⟩. Therefore, the sum of vectors \(\vec{b} + \vec{w}\) is:

\(\langle 0+(-0.5), \, 90+(-0.5) \rangle\)

which equals ⟨-0.5, 89.5⟩.

This result of adding two vectors – the resultant vector – predicts how the ball’s trajectory will look when the strong wind is blowing from the Northeast. As you can see from the animation above, the ball will be displaced to the left. More precisely, for each unit of movement in the y-direction, the ball must be displaced by approximately \(-\frac{0.5}{89.5}\) (around -0.005587) to the x-direction. When the game developer writes program code, they incorporate this displacement into the game algorithm.

### Conclusion:

This was an illustrative example of how vectors can help describe real-world conditions (in the above example, it was wind). The use of vectors helps create realistic games that take into account various real-life factors such as wind, gravity, air resistance, friction, and others.

The ball game is just one example. In reality, vectors can be used in computer games to animate movements of various objects. For example, they can show how a car will move after a collision with an obstacle or another car.

### References:

You can easily check for yourself how important the knowledge of vectors is for game developers. Just try a YouTube search using the keyphrase “vectors for game developers,” and you’ll discover numerous tutorial videos explaining how vectors are used in game development to animate movements in computer games.

Additionally, in order to create this blog post, we analyzed a scientific article about the influence of the wind on the tennis ball:

## Video Version

The video version of this blog post includes more detailed animations showing the trajectories of the ball, illustrating how the ball moves at different time intervals. Additionally, the video version provides more examples of vector addition and considers additional real-life conditions that impact the velocity of the ball, such as air resistance.

Enjoy the preview of the video below, or subscribe to gain access to the full collection of our videos.