Sign in to follow this  

2D Games Maths

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there, I've recently taken to teaching myself how to make simple computer games and have made a pong clone and simple space invaders clone. However for both of those games I had one eye on a tutorial to guide me through the trickier aspects. Now I've decided to make a breakout clone in an earnest attempt to making a game of my own (i.e without following a tutorial). I'm a bit stuck on the maths involved for breakout however. I know the maths is similar to what is in the pong clone as far as making the ball rebound off walls and the paddle, and whatnot. When I was following the pong tutorial, I thought I understood what was going on sufficiently, however when I come to implement similar functionality in breakout I for the life of me can't write the necessary code on my own (without taking a sneak peek at the pong code). I could just copy the code from pong, but that isn't going to solve much with regards to my proper understanding of the topic. I understand this is one problem with following a tutorial, but I don't follow them blindly just racing along to get to the end product, instead I try my best to understand exactly what each line of code is doing and think about how it would be applied to other projects, and have learned a great deal by doing tutorials this way. However I'm getting frustrated at not being able implement the maths involved with what I imagine to be a relatively primitive game. I'm not bad at maths, it was always one of my best subjects at high school, and was competent at university level (only really doing intro calculus) but that was more due to a lack of application rather than a lack of ability (not sure how they made university maths so dull, but they did). I guess my question is what sort of maths is involved in the development of 2D games? I appreciate 'maths' is quite a broad term, and will likely encompass physics and other topics (which always seemed to me like applied maths). I'm not interested in 3D maths at this stage (although there may be a crossover between them, I don't know). Also does anyone have any good starting points for (re)acquainting myself with some of these topics (for example my trig is very hazy)? Also as a windows developer by trade, I appreciate that often it takes practice and experience to be able to just do things off the top of my head. There seems to be a multitude of references for 3D maths, but very little for 2D maths. I'm just a little disheartened at not being able remember (and subsequently recall) the necessary maths involved with something as seemingly simple as rebounding a ball off a wall. Any advice, tips, or references about how to get beyond this next hurdle would be hugely appreciated. Sorry if the topic is a bit muddled, and possibly a bit unclear. Articulation was never one of my strong points. Cheers, Gray

Share this post


Link to post
Share on other sites
I suggest you keep doing what you are doing. Make one game, and then make another, peaking back to get the bits you dont have down. Dont copy+paste them, but read them, go over why you need it, then re-write it. Its just practice. Eventually, (possibly much sooner then you'd expect) you'll find the event of looking back at someing is almost rare.

And the warm fuzzy feeling when you make a game from scratch without a single peek for the first time, is pretty nice if you slug it out.

Just whatever you do, dont stop coding, unless its to play games of course. Or eat, work, sleep etc.

Share this post


Link to post
Share on other sites
Hi there i know how you feel math i snot my overal strong point. So what you need to look up is vector mathamatics. With it you can determine where something will be wether or not two lines intersect witch can be used for determining wther or not the ball has hit something and best off all you can use angels as for when a ball hits a wall the angl einverters based on its direcotionality :) witch can be determined by its angel.

Gamedev.net here has a bunch of math artical you may wish to read up on and it may help clear up some issue you are having.


Regards Jouei.


Remmber to rate pepole on how they help you that is what it is there for.

Share this post


Link to post
Share on other sites
A general understanding of geometry is helpful and Trig is important to help you understand the things you'll be doing with vectors and matrices, which is where the real meat is located.

The specific problem you're trying to solve is known as "reflection" search that term on Wikipedia or a good math site like Wolfram's.

Share this post


Link to post
Share on other sites
If you're a working developer then you probably have an income. A wise investment for you would be to buy an introductory textbook on Calculus & Analytic Geometry. There are literally hundreds available and most are of decent quality. While you *can* find this information online, having it presented in a coherent single source, with worked examples and practice problems, will give you a far more comprehensive understanding of the mathematics, allowing you to apply it liberally in your games programming.

I can recommend Stewart's 'Calculus' text and its companion 'Linear Algebra for Calculus', having used both for many years to teach undergraduate level mathematics.

Beyond the mathematics study, you should read up on kinematics and dynamics, which is the mathematical description of the motion and interaction of physical bodies.

All of this might seem like overkill just to work out how to do a rebound from a wall in your breakout game and if that were your only aim then the above recommendation *is* overkill. However, you stated your interest was in learning how to develop games and for that an understanding of some elementary mathematics is an invaluable skill.

As for the lack of information regarding '2D maths' as opposed to '3D maths', 2D is just a simpler case of the 3D problem. Everything that works in 3D works in 2D and is easier to solve. 2D is often a good way to introduce a problem because it contains the inherent attributes. Ultimately though, most people will simply address the 3D case, simply because it is more relevant to everyday life.

Good luck with your learning,

Timkin

Share this post


Link to post
Share on other sites
Wow, thanks to everyone who took the time to reply!

Thanks Timkin for the book recommendations. My sentiments exactly about a single reference book vs variety of online resources. I had looked into some introductory Maths textbooks, but as you say there is a plethora of options available so thanks for your recommendations, I'll be sure to check them out!

Thanks Ravyne for the suggestion of going to Wolframs, very interesting stuff. Also thanks to everyone else who offered suggestions. You've all given me new key words to google with while I get around to organising a reference text.

Cheers,
Gray

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

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