Using Trigonometric Functions in Game Programming

By: Ali Soltanian Fard Jahromi

What are the Trigonometric Functions?

The trigonometric functions are a set of functions which show the relation between an angle of a right-angle triangle and the ratio of the lengths of two of its sides.  The trigonometric functions are: sine, cosine and tangent.  The trigonometric functions are periodic, meaning that their graphs repeat continuously in a specific pattern. For example, here is the cosine function’s graph:

Uses of the Trig Functions in Game Programming

I am a game developer and a digital artist (CGI, 3D animation, digital art). I have developed and released many games in different genres.  Trigonometric functions can come particularly useful in game programming.  For example, in some games, I have to find a way to implement a day and night system, where the world oscillates between day and night repeatedly as the game progresses.  This repetitive pattern can be represented by the cosine trigonometric function.  The cosine function always results in a number between negative one and one.  In the code for my game, I have a value which represents the brightness of the atmosphere of the environment which can be anywhere from zero to one. To achieve the day and night cycle, I create a variable that is constantly increasing. I then take the cosine of it.  Furthermore, I take the absolute value of that variable so that the value of the variable is never below zero.  The figure below is a model representing the day and night cycle implemented in the game:

The result is a trigonometric function representing the day and night cycle in my game program.

Invasion Resistance 2

To download the game visit the Steam Store link: Invasion Resistance 2.

In the year 2056, 21 years after the failed Zooxian invasion, the Zooxians came back with a stronger invasion force to conquer Earth. The Earth Protection Association was defeated. The sole survivor, Major Stevens, badly injured from his encounter with the Zooxians, contacts his old commanding officer, the Colonel, to take back the planet.

The sequel to Invasion Resistance is more action packed, has improved game-play and 13 maps.

Developer: Ali Soltanian Fard Jahromi

Graphics: Ali Soltanian Fard Jahromi

Cut-scenes: Ali Soltanian Fard Jahromi

Game-play screenshots: