Sign in to follow this  
Thomas Wiborg

Where to learn 2D Math for game dev

Recommended Posts

What kind of Math do I need to learn in order to make the games listed under.
And where can I learn this kind of math, are there any newbie sites, book etc, that isent very hard?

- Terraria
- Mario

- Diablo 1 and 2 Isometric
- Plant vs Zombie
- Zelda 2D RPG

Edited by Thomas Wiborg

Share this post


Link to post
Share on other sites

Just learn linear algebra and analytic gemetry (not sure if thats how you call it in english).

Both are really sumple, just take a bit time to master it. After you learn those things you will know what to learn next.

Additionally learn calculus :)

Share this post


Link to post
Share on other sites

Basic graph theory and trigonometry, arithmetic. Khan Academy should have everything you want.

Do you have experience programming? If not, you'd probably be better off learning that first. This article outlines some good projects to start with, which you can tackle before trying some of the more advanced stuff you mentioned in your post.

Yep I can program. Thanks for the tips!

Share this post


Link to post
Share on other sites

There are a lot of books about the matter also. This book is the one I used in my college course: Fundamentals of Math and Physics for Game Programmers by Wendy Stahler.

Yes, I know you asked for 2D, but I'm going to add this in case you move to 3D for any reason.

There is also 3D Math Primer for Graphics and Game Development by Fletcher Dunn; again; in case you are interested in 3D. 

There are other books as well, but I've not read any of them to be able to recommend any other book.

Edited by BHXSpecter

Share this post


Link to post
Share on other sites

start with 2d Cartesian coordinate systems, 2d vectors, and basic trig.

 

some analytic geometry (beyond the basics listed above) may be of some use at some point.

 

then you can move on to 3d and linear algebra.

 

calculus - haven't found much use for it myself.

 

and i've taken just about every math class ever invented (all the way through differential equations).

 

and liner is not easy. and i got an A in linear. <g>.

Share this post


Link to post
Share on other sites

calculus - haven't found much use for it myself.

 

Calculus is one of those fun subjects that you don't appreciate it until you need it, then it is amazing.

 

Vector calculus is used all the time in both graphics and physics. If you want to deform objects in graphics, to make their normals work out you need to figure out how the deformations change the shape and then change the normals appropriately. Same thing in physics, parametric shapes are defined by math functions, and figuring out angles to bounce and otherwise react with requires calculus to figure out the formulas.

 

... Either that or you can look up the existing formulas as best you can, and just assume that they did it all right instead of actually know the math yourself.

 

Splines in general are calculus, but again many programmers don't bother to understand the math, just search out a formula they can run against a matrix multiply to get their results.

 

Many game programmers get by with iterative methods and accumulating values.  It is more precise to compute the endpoints and the rates of change, then directly compute the intermediate rather than accumulating the values (and also accumulating the error).  But a little bit of simple calculus as you implement the system lets you implement directly and then solve in the middle.  

 

 

Any time you are using an iterative solution, like accumulating a tiny bit of motion every update, it is usually better to figure out the proper math for it.  Accumulated values also accumulate error, and once you've added a tiny number for a few minutes your accumulated error quickly becomes significant.  Better for the programmer to find the rate of change (that's usually calculus!) and then write a function to compute the value directly.

Share this post


Link to post
Share on other sites

calculus - haven't found much use for it myself.

derivatives can be used to calculate surface normals from a displacement map. I suppose integrals could be used to do the reverse.
You've almost certainly used Euler's method in the form of velocity += (acceleration * time); position += (velocity * time); etc. It's a method for solving differential equations quickly.
I've used Taylor expansions to implement extremely fast trig function approximations. Taylor expansions represent functions as a series of infinite sums (but in trig functions, only the first few are of significance for 0 < x < pi/2) calculated from its derivatives.


As for the OP, any math site should be able to teach you the concepts. For 2D games, you only need trig and geometry, although basic linear algebra wouldn't hurt.

Edited by nfries88

Share this post


Link to post
Share on other sites

I think the guys above already listed most of what you want, so I could just add that you can also find a lot of good material at stackoverflow just by googling for specific topics (example: c++ angle between two vectors, etc...)

 

I would like to make a comment on the games you listed though, as I think you should rearrenge them a bit with concern to the math required. I assume you didn't really set any specific order to them when you wrote it down but I would consider something like this

 

- Mario (simple physics, not to much shannanigans, mostly algebra and some trig)

- Zelda 2D RPG (a bit more physics involved which means you need dive a bit deeper into that field)

- Terraria (Here you also start going into the procedual generation which is really a area of its own, more statistics than algebra/physics)
- Diablo 1 and 2 Isometric (Procedual generation as well as more advanced physics to have all interaction with skills/effects creatures etc as well as more math to generate the visual effects)

- Plant vs Zombie Well, I haven't played it, dont know how to rank it ^_^

 

 

So, for the games listed In my mind there are actually three (or four) seperate fields linear algebra/trig., statistics for procedual generation as well as physics (mainly mechanical, forces, impluses etc). So I would highly reccomend you start with the case with the simplest physics etc to just get used to the math tools you require, as soon as you start feeling a bit more confident try adding a bit more physics effects etc and start moving on from there

 

 

Ah, and don't be discuraged if a simple thing such as getting two blocks to collide, bounce or even rotate after the collision gives you a really hard time, some seemingly simple things can have some tricky physics (for a beginner) but it's all part of learning ^_^

 
 

Share this post


Link to post
Share on other sites

I would modify the list of games yet again to incorporate this list of games from this article. I think the list will help slowly build on skills and math to make each new game a little easier to make.

 

  • Pong = Simple: input, physics, collision detection, sound; scoring
  • Worm = Placement of random powerups, handling of screen boundaries, worm data structure
  • Breakout = Lessons of pong, powerups, maps (brick arrangements)
  • Missile Command = targeting; simple enemy ai, movement, and sound
  • Space Invaders = simple movement for player and enemy, very similar to breakout with the exception that the enemy constantly moves downward, simple sound
  • Asteroids = asteroids (enemies) and player can move in all directions, asteroids appear and move randomly, simple sound
  • Tetris = block design, clearing the lines, scoring, simple animation
  • Pac Man = simple animation, input, collision detection, maps (level design), ai
  • Ikari Warriors = top down view, enemy ai, powerups, scoring, collision detection, maps (level design), input, sound, boss ai
  • Super Mario Bros = lessons of Ikari Warriors (except with side-view instead of top-down view), acceleration, jumping, platforms
  • Legend of Zelda
  • Terraria
  • Diablo 1 & 2
  • Plant vs Zombie

I think that will cover the major concepts and also build skills while you are at it.

Share this post


Link to post
Share on other sites

I did a collection of common 2D gamedev math recipes, covering the basics like moving in a given direction, orbiting an object, rotating to face an object, collision boxes and circles.  Basically 99% of the math you need to make a basic 2D game.  

 

If you run into trouble and need to move beyond the basics, Khan academy is a very good source.  For me, my ancient OAC calculus textbook has been invaluable believe it or not.  Granted, there is no such thing as OAC anymore, so that's not a lot of help....  these days it would be about the same as a 101 level course I believe.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this