# Math and 2D game development

This topic is 2147 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello there sorry for the silly question but I prefer some advices than just going ahead. Recently I started learning how to make simple 2D games.
First one I made was tic tac toe and then I started working on pong but its not finished yet. Im pretty much aware that math is quite an important part of video game development and I just want to ask you guys which branches of mathematics are the most vital ones when it comes to 2D game development .. Lets say for example a simple side scrolling game with a very basic physics engine. And what math/physics will it be required in order to . lets say make it smoother and with better physics , sorry again for the lame question it`s just I feel quite confused atm.Really looking forward to your replies !

##### Share on other sites
For 2D geometric computations in general, knowing your complex numbers in and out can be very helpful.

For Physics, you should learn a bit about how to integrate differential equations numerically (Euler method is the most basic way to do it, and verlet integration is also simple are has some neat properties). It is a difficult subject, but you really need to understand very little of it for a 2D side-scrolling game.

##### Share on other sites
Yeah I know that video game development is not easy at all but I have to start from somewhere

##### Share on other sites
If you want physics, at the very least, you'll need multivariable calculus and linear algebra.

##### Share on other sites
The thing is, you don't really need in-depth knowledge of any given field. You end up cherry-picking a few bits here and there. And like alvaro said, you don't necessarily need to understand it all, as long as you can at least get it functional. Additionally, if you start on a game project of any significant length, there will come a time when you no longer deal with the math at all. Once the framework is done, and you are well into the content generation phase, it is entirely possible that you will forget everything you knew about linear algebra and calculus as regards game development, such that when you start writing the next framework you have to learn it all over again. Happens to me all the time.

Also, don't postpone working on anything until after you feel you know all the math you'll need. Getting a project to work offers a fantastic learning experience to help you pick up the knowledge as you go. You'll go into it a math noob and come out... well, maybe still a noob, but at least a noob with a working 2D game framework under his belt and a better grasp on things than before.

##### Share on other sites
can you guys give me a simple example a chunk of code for what complex numbers can be used ?

##### Share on other sites
I've never used complex numbers in anything I've done in 2d game development.

Here is a maths primer I wrote for game developers: http://www.wildbunny.co.uk/blog/vector-maths-a-primer-for-games-programmers/

It should give you some pointers

##### Share on other sites
Lots of trigonometry.

##### Share on other sites
Seriously, guys, the answer to the OP's question is trig. To make a 2d side-scrolling game you need to know at least trigonometry. I know the OP mentioned physics but unless we hear otherwise I think we can assume he means very simple physics i.e. how much calculus do you need to implement the physics in a game like Super Mario Bros. 3?

##### Share on other sites
Why do you think trigonometry is needed? You can stay away from using angles pretty much all the time, and code tends to be simpler and have fewer special cases when you do.

The jumping in Super Mario Bros. 3 looks like a hack, but the way the response of the controller to horizontal input probably requires some familiarity with calculus. Enough that you can then change the frame rate without affecting the experience too much, for example.

##### Share on other sites

Why do you think trigonometry is needed? You can stay away from using angles pretty much all the time, and code tends to be simpler and have fewer special cases when you do.

Unless of course, you have anything involving rotation or aiming.

##### Share on other sites

[quote name='alvaro' timestamp='1333562116' post='4928257']
Why do you think trigonometry is needed? You can stay away from using angles pretty much all the time, and code tends to be simpler and have fewer special cases when you do.

Unless of course, you have anything involving rotation or aiming.
[/quote]

No, even then you are usually better off using complex numbers or vectors instead.

##### Share on other sites

Why do you think trigonometry is needed? You can stay away from using angles pretty much all the time, and code tends to be simpler and have fewer special cases when you do.

The jumping in Super Mario Bros. 3 looks like a hack, but the way the response of the controller to horizontal input probably requires some familiarity with calculus. Enough that you can then change the frame rate without affecting the experience too much, for example.

Well, I guess it depends on the requirements of the game in question. I was thinking it would be good to know how to get horizontal and vertical components of a vector given an angle for jumping or shooting, say. But, yeah, all of that sort of stuff could obviously be done by defining things in terms of horz and vert offsets rather than angles -- in this case I'd say you need to at least have a solid understanding of algebra.

Look, it wouldn't be bad to have familiarity with calculus but to say that in order to make a relatively simple game you need to know calculus, I mean, I think that is just clearly false.

It depends if the OP is looking for the minimum math needed to get started or for a course of study. If you want to deal with non-trivial physics then you need a background in calculus and so forth. If you want to make something like Super Mario Bros. you need to be comfortable with junior high school level analytic geometry.

##### Share on other sites

No, even then you are usually better off using complex numbers or vectors instead.

Using vectors is usually better, but you can't use them for every purpose. For example, suppose the player can aim in different directions by pressing left and right. You'd expect that pressing left followed by right will leave you facing in the same direction you were before. You can't use a vector because doing so will accumulate rounding errors, so you'll never return to the same position. In that case the only possible representation is an angle.
Basically, for physically simulated rotation, vectors are better, while for rotation that comes directly from the UI, angles are better.

Anyway, I consider udnerstanding of unit vectors and rotation matrices to be trigonometry anyway, so it doesn't really matter.