Jump to content


Photo

Mathematics in game making


  • This topic is locked This topic is locked
65 replies to this topic

#41 Gamer3D

Gamer3D

    Human* me = this;

  • GMC Member
  • 1589 posts
  • Version:GM8.1

Posted 18 July 2011 - 06:55 PM

Another thing to think about; suppose you have made a very complex algorithm for doing something. It seems to work in every case, but you're not sure. How would you make sure it works? Has anyone ever had a situation where they actually did a formal proof to show that something worked?

This is game making (I.E. no need for precision, and it's often better to fake things than to create a foolproof solution). Unless you're making a library for someone else to use, it's usually safe to test it on the range of conditions that you expect.

For example, a short time ago, I created a bot aiming system for an FPS (Using finite-speed projectiles, gravity possible on projectile/target/both). I had some options:
  • Quartic formula (Foolproof solution)
  • Quadratic formula (Works unless projectiles have gravity or the target is falling, but is much cheaper than quartic)
  • Iterative solution. Guess where to aim, improve guess based on error in original guess. (There's no guarantee that this will find the best solution, especially since I'll only let it guess 4 times or so)
  • Hybrid.

Long story short, I use a quadratic to find the starting point, then an iterative solution to hit falling targets. There's no proof that it'll work all the time, but if it fails, it'll just cause the bot to miss (Which is expected by most players anyway, so no harm done).
  • 0

#42 NikaB

NikaB

    GMC Member

  • New Member
  • 111 posts
  • Version:GM8

Posted 19 July 2011 - 06:14 AM

Well, the most basic use of "not extremly simple" mathematics is the angle calculation. In my opinion, geometry is more needed in game making than pure algebra, because you are making something which must be seen and understood.
See : If you are making a TDS and your character isn't rotating... :/
So, "complicated" mathematics are more needed (in game making) to make physics. They also allow you to operate with very high level algebra and/or arithmetic; but in my opinion it's an aspect of maths probably unused (in general) in game making.

Concerning me, mathematics is the only thing I need to learn to be more "expert" in programming. Because I'm only 8th grade, 14 years old, and the most complicated thing I can do for the moment in geometry, is the bases of trigonometry, Pythagoras, Thales etc... I'm now entering to 9th grade and I think I will really learn a LOT of stuff needed for programming.
:D
So exciting for me !
  • 0

#43 No Eyed Fsh

No Eyed Fsh

    GMC Member

  • New Member
  • 24 posts

Posted 06 September 2011 - 09:30 AM

In GM, knowledge of stuff like trig isn't strictly necesssery. This is because many of the things that trig is normally used for are already put into build in functions.

Take

imageAngle = pointTo(mouse_x, mouse_y);
(I'm pretty sure I got the syntax wrong)...

If you were to look at the code behing pointTo(), you would see something like this:

imageAngle = atan2((mouse_y - y) , (mouse_x - x))

  • 0

#44 drt_t1gg3r

drt_t1gg3r

    GMC Member

  • GMC Member
  • 3230 posts
  • Version:Unknown

Posted 18 October 2011 - 11:36 PM

EDIT: cut quotes and comments that was not related to my reply
.
.

So...you're saying "game developers don't need to worry about advanced math because other game developers will worry about it for them"? I suppose that's true of anyone in any profession. "Surgeons don't need to worry about medicine because their assistants can worry about it for them." While true, it's a poor outlook on life.

-IMP ;) :)

IMP, out of the current 3 pages of replies this is the one that set me aside a bit. How can one say 'it's a poor outlook on life' when we no longer re-create the wheel? What has been done and perfected is surely done an no longer needed to recreate for no other purpose than the individual's need to do so. I understand binary a little but no longer is it a must have to create simple games. Assembly language isn't either to my knowledge. [dot]Net has libraries upon libraries that help the designer so we don't have to recreate it.
  • 0

#45 mechlore

mechlore

    GMC Member

  • New Member
  • 52 posts

Posted 19 October 2011 - 12:20 AM

Ive always been pretty terrible at math, and I created about as complex of a game as you can create in gamemaker (called MechLore, im on google now so if you google MechLore as one word you'll find it).


You would be surprised at how little advanced math you need to know to do fairly complex things with gamemaker style middleware. (ISOMETRIC) Archs for example - in my game use no math or physics but behave as though they do. Its really just a matter of applying what you do know, in this case, that every step the arching object needs to go upwards... but slow and reach 0 towards the top, before accelerating downwards again. With gamemaker you dont need to know physics, you just need to know, basically, how to move objects.


Note: Im basing this off my experience with math in highschool, I recently took a math class (that im in right now actually) and im averaging 99%, it actually feels really really easy... so.. Maybe I've always been good at math, just bad at learning it in highschool or using gamemaker has vastly improved my propensity for learning math.

Edited by mechlore, 19 October 2011 - 12:23 AM.

  • 0

#46 chance

chance

    GMC Member

  • Reviewer
  • 5765 posts
  • Version:GM:Studio

Posted 19 October 2011 - 11:43 AM

I recently took a math class (that im in right now actually) and im averaging 99%, it actually feels really really easy... so.. Maybe I've always been good at math, just bad at learning it in highschool or using gamemaker has vastly improved my propensity for learning math.

Yes to emphasis. Game making and mathematics both expand your learning ability. They enhance creativity, logical thinking, and systematic problem solving.

Even if you don't apply mathematics directly to your games, prior study of mathematics improves your reasoning skills and lets you make better games.
  • 1

#47 MortimerInBlack

MortimerInBlack

    GMC Member

  • New Member
  • 138 posts

Posted 11 November 2011 - 02:57 AM

Hey, nice topic, and I have an example for you. Write a function called "function_angle_difference(ang1, ang2)" that takes 2 angles and returns their difference (the smallest angle between them). Example: function_angle_difference(45, 100) returns 55.

But you cannot simply take the absolute value of the difference because what if the 2 angles are across the 0 degree line? As it turns out, the algorithm/math is fairly complicated. I won't write the solution here so that Maurice can try it, but the answer is here: http://www.gmlscript...ngle_difference

Who knows? Maybe there's another solution to that with a simple if/else. My point is, a simple question like "what's the difference between 2 angles?" can lead to complicated formulas. But another point is you can just use script libraries as long as you understand what they do and what restrictions they may have, because I never figured that out and just got it from GML scripts.

I've needed the angle difference function for certain AI and path finding. You can't always just use point_direction because realistic objects need to take time to turn towards a point, and you have to know how long that will take.

Anyway, I'm probably biased because I've tutored math on and off for 2 years now, plus I'm good at it, plus I appreciate my bachelor's degree in CS and the master's I am seeking now, plus other stuff I can't think of right now, such as I often write simulations of real-world things for my own enjoyment like space and orbit simulators.

The most complicated thing I've made with GM is probably that remake of Commander Keen (a 2D isometric platformer with ledge-grabbing, pole-climbing, moving platforms, and shooting in many different states on all those objects). It involved very little math. A close second would be certain space and orbit simulations, which as you can imagine involved fairly heavy math for both geometry and physics (gravity).

So my ultimate point is this: writing games and learning how to write games is about figuring out problems and how those problems work in the game language. Whether or not the problem involves advanced math or even any math at all is dependent on the problem itself. Certain genres of games will be more math-intense than others.
  • 0

#48 numbers

numbers

    GMC Member

  • New Member
  • 460 posts

Posted 15 November 2011 - 05:07 AM

what if you want to program AI of some kind? Neural nets need math. If you want fast collision detection, the GJK algorithm definitely needs math. Typically, you don't need math if you go with the most naive algorithm you come up with, but it'll take some kind of mathematical analysis if you want to reduce the problem into a simpler one, or to create an efficient algorithm. You can't work with a system that's entirely based on numbers and then claim that you don't need math. Graph theory, bayesian probability, functional analysis, it all helps when you want to do a more complicated project. Don't assume that it doesn't count as math just because you aren't crunching numbers. Gradeschool "math" doesn't really give you a sense of the broad applications or the real nature of higher level mathematics, and you've likely touched on the basics of some of these concepts without realizing it.
  • 0

#49 ean

ean

    GMC Member

  • New Member
  • 190 posts
  • Version:GM8

Posted 27 November 2011 - 04:30 PM

My game making teacher doesn't have a math degree but after some debate they let him teach anyway. He also teaches Direct X.
  • 0

#50 Desert Dog

Desert Dog

    GMC Member

  • Global Moderators
  • 6409 posts
  • Version:Unknown

Posted 27 November 2011 - 09:07 PM

I came across this article/tutorial while googling around once:
The Use of Mathematics in Computer Games
  • 0

#51 @Alex@

@Alex@

    Retired GMC Reviewer

  • Reviewer
  • 3059 posts
  • Version:Unknown

Posted 27 November 2011 - 09:28 PM

Desert Dog, it's a nice find if a little outdated "Quake III, one of the newest FPS games around" . Outdated probably isn't the best word condsidering everything it covers is still perfectably valid.
  • 0

#52 lmbarns

lmbarns

    GMC Member

  • GMC Member
  • 60 posts
  • Version:GM:HTML5

Posted 17 December 2011 - 05:49 PM

lol I had to use trig this week starting from a point of not knowing what I needed....I started with the Pythagorean theorem only to realize that was giving me only the distance between two points but not the direction.

Eventually, for the first time in my life......I actually had to use trig for something I was interested in! It was mind blowing and I wish it was introduced to it in school with a practical application....like figuring out the angle between 2 points to shoot in video games using notepad...I would have perked up at that.

Really simple code:

function getPlayer() {
Angle = Math.atan2( hero.x - monster.x, hero.y - monster.y);
Sin = Math.sin(Angle) * Per_Frame_Distance;
Cos = Math.cos(Angle) * Per_Frame_Distance;
monster.x += Sin;
monster.y += Cos;
}
  • 0

#53 TheSnidr

TheSnidr

    That guy

  • Global Moderators
  • 2436 posts
  • Version:GM:Studio

Posted 17 December 2011 - 06:57 PM

Hm... Actually, using trigonometry isn't needed in that case. I'm glad you figured out that trigonometry could be used though, and I'd like to add that it's useful in a lot of other areas of game making too!
A simpler way of doing what you're doing now is normalizing the direction vector and multiply it by the per_frame_distance. In gml code it'd be like this:
_x=hero.x-monster.x
_y=hero.y-monster.y
l=Per_Frame_Distance/max(sqrt(sqr(_x)+sqr(_y)),0.0001)
monster.x+=_x*l
monster.y+=_y*l

  • 0

#54 salaH

salaH

    GMC Member

  • New Member
  • 29 posts
  • Version:Unknown

Posted 22 December 2011 - 10:06 AM

math is really overrated. I feel sorry for the people who spends years learning it at advanced levels. today you dont need to know those things to create a good game because you already have the predefined functions. why reinvent the wheel?
  • 0

#55 NakedPaulToast

NakedPaulToast

    GM Studio/Mac/Win

  • GMC Member
  • 7192 posts
  • Version:GM:Studio

Posted 22 December 2011 - 07:02 PM

math is really overrated. I feel sorry for the people who spends years learning it at advanced levels. today you dont need to know those things to create a good game because you already have the predefined functions. why reinvent the wheel?

I am completely astounded that you would post this, then within a half an hour create the following topic, in an experts forum no less.

http://gmc.yoyogames...howtopic=527525

I was wondering if anyone has experience creating card games. what functions or formulas are useful, etc.?

lets say that you have 52 cards and you divide them among 4 players in a game like poker. the ai players would need some level of intelligence.


If you had an appreciation and desire for improving you math skills, instead of feeling sorry for people who have a greater understanding of math, then you would not need to have to ask for a function or formula. You would be able to figure one out.

Edited by NakedPaulToast, 22 December 2011 - 07:03 PM.

  • 3

#56 DZiW

DZiW

    GMC Member

  • GMC Member
  • 727 posts

Posted 22 December 2011 - 11:07 PM

Indeed, math + logic = game interactions, where all the items are but its components one should consider.
If such 'engine' is quite simple then it's ok to use simple math, but when it comes to more complex things then it's not often possible to break down this megaformula as more simple interactions.

Hey, without math it must be something rather oversimplified (although sometimes it's ok for the of speed and accuracy). For instance, recently I tried to add some artificial strategy, but had to give up, because it would take forever to find (almost) the best approach how to use the current amount of resources the most efficient way to build the army, and then I remembered how we solved similar tasks in economics and used a couple of abbreviated multiplication--so it was a piece of cake to let CPU build the most powerful army available--pure math! Also I could see when the situation could turn unsafe (e.g. zero divide, extremum, limits, etc.) How could one do it without math? Just teach your AI for several years or randomize?! Jeez, man - it's just numbers, everything PC can process is but numbers. And if they do interact somehow then there're certain rules or equations.

So I strongly believe that math is a must when it comes to sensible and reasonable solving of any issue, including gamedev.

Else one has to use random values to 'fake' real math. IMO)
  • 1

#57 Captain Mangoes

Captain Mangoes

    GMC Member

  • GMC Member
  • 117 posts

Posted 05 June 2012 - 11:06 AM

There are many existing code bases for plenty of awesome functionality which don't require a heavy knowledge of maths to use. They are, however, all written by people who knew their maths. Sure, you could get by without knowing much/any maths, but then in the words of the mighty Mark Overmars "don't expect to make the next Quake". Meanwhile people who took the time to learn their stuff are making the next Quake, so do you just want to make games or really lead the field? Real programmers aren't afraid of maths.
  • 1

#58 masterofhisowndomain

masterofhisowndomain

    The Designer

  • GMC Member
  • 3639 posts
  • Version:GM8.1

Posted 05 June 2012 - 02:12 PM

My game making teacher doesn't have a math degree but after some debate they let him teach anyway. He also teaches Direct X.

That's a different debate though: professional qualification vs. autodidacticism. Plenty of people who never go to university acquire skill and knowledge in a subject area that matches those who have.
  • 0

#59 slayer 64

slayer 64

    GMC Member

  • GMC Member
  • 3275 posts
  • Version:GM8.1

Posted 18 June 2012 - 03:10 AM

you don't need maths to make games
  • -3

#60 NicroGames

NicroGames

    GMC Member

  • GMC Member
  • 296 posts
  • Version:GM:Studio

Posted 19 June 2012 - 05:40 AM

you don't need maths to make games

You do! Have you ever used the "direction" variable, or maybe the "lengthdir" functions? That's math. What about changing the x/y position? That's also math... Made a healthbar? Math, math, math... :wacko:
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users