00:00
00:00
Newgrounds Background Image Theme

Someone gifted MetalSlayer69 supporter status!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Math and physics needed for web games?

461 Views | 4 Replies
New Topic Respond to this Topic

I want to brush up a bit on my math and physics if I wish to possibly in the future make a few games here and there just for newgrounds. 3D games most likely won't be happening until web browsers can handle it better, but what about for 2D or 2.5D games? I got the following on my mind for what to freshen up on (in no particular order):

  • Linear Algebra
  • Calculus
  • Geometry
  • Discrete Math
  • Statistics and Probability
  • Trigonometry
  • Physics in general

What areas of math and physics are necessary for 2D and 2.5D games? And is there a certain order I should re-learn it at. Mind you I'm not going to be making AAA tier games because of browser limitations, but still should know enough math to make something really fun.


Honestly unless you're writing your own physics and/or rendering engine you don't really need to have a deep knowledge of math or physics for writing a web game, since most engines already handle that for you. Back in the day it used to be libraries like Box2D and its ports, nowadays it's built in to frameworks like Phaser and so on.


There's nothing wrong with learning math and physics for building things yourself, or to get a deeper understanding of how things work (so that you can break the rules, as it were) but for most purposes you won't need that knowledge. And you can always look them up as and when you do.


It's the same with deep learning - you need to know the maths (calculus + statistics) behind it if you're trying to create new neural architectures, or if you're trying to improve existing ones. But if you're looking for off-the-shelf solutions, then most libraries can handle the hard parts and give you something that works reasonably well, even if you don't quite fully understand how it works. That's one of the advantages (and disadvantages) of abstraction.


And if you ask me, buying into the idea that you need to learn X before you can do Y when it's not needed just provides ways to duck out of doing Y directly - e.g. people saying they're not good at math so they shouldn't bother learning programming, etc. Not saying that applies to you, but it is a common refrain I heard a lot in the past.


Also, 3D-for-the web has come quite a ways since the last decade or so, they run fairly smoothly even on integrated graphics these days. Part of it comes down to mobile GPUs becoming far better, but part of it is also the better ecosystem around getting JS as close to bare metal where needed (e.g. with wasm, webgpu, etc.)


Slint approves of me! | "This is Newgrounds.com, not Disney.com" - WadeFulp

"Sit look rub panda" - Alan Davies

BBS Signature

Response to Math and physics needed for web games? 2023-07-30 12:56:55


At 7/8/23 08:50 AM, lwpage wrote: I want to brush up a bit on my math and physics if I wish to possibly in the future make a few games here and there just for newgrounds. 3D games most likely won't be happening until web browsers can handle it better, but what about for 2D or 2.5D games? I got the following on my mind for what to freshen up on (in no particular order):
What areas of math and physics are necessary for 2D and 2.5D games? And is there a certain order I should re-learn it at. Mind you I'm not going to be making AAA tier games because of browser limitations, but still should know enough math to make something really fun.


No.

Response to Math and physics needed for web games? 2023-07-31 01:34:39


a watered-down algebra-based physics should be plenty if your game is actually going to incorporate physics. Namely programming kinematics. As Gimmick said, the engine will handle all the heavy lifting.

all programmers should have a rudimentary understanding of discrete math and set theory.


BBS Signature

In general, programming a game is its own sort of skillset that has maybe some but not a lot of overlap with other math and science stuff. Like Gimmick said, if you want to make or modify your own engine or graphics renderer then that's one thing. But if you just want to make a game using an engine that is set up to do most of that (Godot or Unity or even HaxeFlixel or Phaser), then the engine will handle stuff for you. Specific comments:


  • Linear Algebra - do not need
  • Calculus - you don't need to actually do calculus yourself. If you're familiar with concepts of integration and differentiation then that's nice, but often you'll have code like

acceleration = force1 + force2

velocity =+ acceleration

if on floor velocity.y = 0

if hit wall velocity.x = 0

position += velocity

Which I wouldn't consider as needing to know calculus for

  • Geometry - it can help to know what a normalized vector is (pointing in the same direction but forced to have a length of 1). I took some advanced geometry and actually used dot and cross products when I wanted to do some custom calculations for Cat's Eye. But most engines have functions that will calculate angles between vectors for you which would make it unnecessary, so I probably didn't need to do it that way.
  • Discrete Math - you should know what a modulo is, and that if you generate a random integer in a large range and calculate it mod N, then you end up with a random integer in the range from 0 to N-1
  • Statistics and Probability - you do probability in programming by generating a random number and having statements like

if rand_num < 0.4

slash_attack()

elif rand_num < 0.7

headbutt()

elif rand_num < 0.9

haruken()

else

heal_self()

  • Trigonometry - it might be helpful to know what a sine and cosine are, but I think I've mostly used them to make wavy changes in some parameter like color or light intensity, not for actually calculating physics
  • Physics in general - see Calculus. And if you want to have a gravity generator, then you should know that you can calculate the vector from player_coordinates to star_coordinates by saying vector_to_star = (star_coordinates - player_coordinates) and then having star_gravity = vector_to_star.normalized * (1 / vector_to_star.length)^2


You now know all the advanced math you need to know for programming a web game.


Things not listed are that you need to know that an array of size N has elements numbered from 0 (not 1) to N-1 (not N). So if you're using C you can say for(i=0; i<N; i++) { } and that will loop over all elements up to and including the last one in an array of size N. And you will get a fuckup if you try to access element number N of an array of size N, and you won't have things work like you want if you access element number Y without remembering that it's the (Y+1)th element. Also, you will need to learn the difference between global coordinate systems and local (with respect to some object in the game) coordinates because that will mess you up nice and good at some point especially if you transition to 3D.


My newsfeed has random GameDev tips & tricks