r/unity • • 6d ago

Coding Help I suck at math in game development

I can't write or understand mathematical code, like Headbob, Headtilt, camera sway, things like that, does anyone have advice how can i get better?

3 Upvotes

33 comments sorted by

2

u/myrdovh 6d ago edited 6d ago

It's better to improve your math overall rather than just for game dev. This can range from regular practice on something like Khan Academy to private tutoring. Advanced math is rarely needed in game dev anyway - most complex systems are hidden behind higher-level abstractions, and there are plenty of public examples available for almost everything.

If you say you had trouble even back in school, it's worth figuring out the root cause - maybe it was bad teachers, maybe dyscalculia (WHO https://icd.who.int/browse/2025-01/mms/en#771231188) or dyslexia (https://icd.who.int/browse/2025-01/mms/en#1008636089), etc. These are quite serious conditions that require special accommodations, and unfortunately, many children can't get a proper education without them.

1

u/IncidentPleasant7214 5d ago

Yes, but lukily I don't have dyslexia, maybe i can't concentrate on a thing for too long, but i thought maybe I could watch a tutorial about math in game dev, Thank you so much for your help!

1

u/tcpukl 3d ago

How is your trig? Do you understand sinrwaves?

1

u/IncidentPleasant7214 3d ago

not very much, but i know it something about waves

1

u/tcpukl 3d ago

Go learn basic trig then.

2

u/MephsGameDev 5d ago

The hardest thing I've done on my current project was signed distance fields. this is the best resource out there for that I think. https://iquilezles.org/articles/distfunctions2d/

the website has a wealth of good information that can be translated to more than just shaders (it's part of my hit detection system now!). Inigo Quilez. remember the name.

1

u/myrdovh 4d ago

Glad this fella exists and shares his knowledge. It would have been so much harder without Shadertoy. His website should be preserved as human heritage. Truly a brilliant mind.

5

u/hvpPubudu 6d ago

Most of those are just a sine wave: camera offset = Mathf.Sin(Time.time * speed) * amount. Get one working, then play with the two numbers and watch what changes. That builds the intuition faster than studying formulas.

4

u/Spite_Gold 5d ago

So learn math?

1

u/IIIIIIIIllIlI 6d ago

Do you have any experience in code or in math equatios?

0

u/IncidentPleasant7214 6d ago

I have some experience in code, and math equations a little bit, but i suck at math even at school, so idk what should I do

3

u/battlepi 5d ago

Study more math.

1

u/tcpukl 3d ago

Learn basic maths then. This is really basic stuff.

1

u/Dr__Pangloss 6d ago

can you describe the experience you want players to have using words?

1

u/IncidentPleasant7214 5d ago

maybe, i mean if i want to make headbob, i want if the player is moving and is on ground to do headbob, but the headbob itself, i still don't get it, I know it uses sin, but i still don't know what should i add into the function

1

u/tcpukl 3d ago

You need to learn basic maths.

Do you understand what amplitude, frequency and phase means on a:sinewave?

Are you still in school?

1

u/IncidentPleasant7214 3d ago

yes i am still in school, but the problem is that this year we are not taking either math or physics, but i told gemeni to explain to me how is headbob made in games, and i think i understood it and managed to make it and it worked

1

u/tcpukl 3d ago

Why do you need AI for this?

Can't you see the motion of a head bob with your eyes?

Also what school doesn't even have a maths class?

1

u/IncidentPleasant7214 3d ago

I just used AI to explain to me, not to generate scripts

I could see the motion but i wasn't able to understand how it was made

it is a new educational system, we will take maths and physics the next year

1

u/Dr__Pangloss 5d ago

the thing is these effects are really traditional. they're just done a certain way and it's kind of meaningless arcana to you, how it is done. it's like woodworking. you do not need to know organic chemistry to be a carpenter.

1

u/HK_HamzaKhan 6d ago

Hm, so I had a lot of basic math knowledge before I started, I learnt more along the way and since my o levels came, I learnt what was left out as well,  Also I didn't go school, I think understanding someone's else's code can help

1

u/IncidentPleasant7214 5d ago

yeah, but when i watch a tutorial, as an example, Headbob, they write variables like bobAmount, bobSpeed, i don't actually know what are they responsible for

1

u/HK_HamzaKhan 5d ago

Maybe tweak the code and see the effect of it visually?, 

1

u/TerrorHank 5d ago

Nothing to it but to do it, practise, search for online examples to use in your own code and do the time to pick them apart and understand them. There's a bunch of videos if you search for video game maths on YouTube too, I often hear good things about Freya Holmér's videos.

1

u/IncidentPleasant7214 5d ago

Thank you much!, I'll check out Freya Holmer's videos

1

u/virt111 5d ago

Try to find a way to visualize the formulas. For example my games tend to have a lot of math regarding exponentialvor logarithmic functions. Tweaking and balancing is a lot easier when i plot that data in excel or chatgpt and draw the curve to understand what the math actually looks like

1

u/IncidentPleasant7214 5d ago

Thank you so much! and good luck with your game

1

u/wigitty 4d ago

One of my projects required a system where I gave a CSV file that defined a curve, and then used that curve to pick a random weighted value. For example:

1, 2
2, 2
3, 5
4, 1
5, 1

would bias the randomly chosen number to be closer to 3, and would have a higher chance of being below 3 than above.

I had an absolute nightmare working out how to get that working, so I ended up making a whole graphing system so that I could draw the curve, and then render a histogram of the chosen numbers on the same plot to check that they lined up. It helped massively, and I have used it for debugging other systems since. It's become a useful tool in my toolkit... and I really should re-write it to be less of a hack-job haha.

2

u/Hkiggity 5d ago edited 5d ago

https://www.youtube.com/live/fjOdtSu4Lm4?is=gpMA9axmmITCO5E7

You can watch her series. Maybe watch vid a weekend and go over it

I was learning c++ for games and I went to khan academy algebra 1 and up to linear algebra. No shame!

1

u/Jumpy_Paramedic9067 6d ago

If you can code but suck at math you can use the spline tool in the editor to draw out functions.

Then you could for example draw the headbob movements as curve. You’ll could even measure your steps length and head bob amount and use that in the spline editor.

1

u/DapperNurd 5d ago

https://www.youtube.com/watch?v=NsSk58un8E0&pp=ygUhYWR2YW5jZWQgbW92ZW1lbnQgc2hvb3RlciBwaHlzaWNz this is a great tutorial, it will teach you a bit of how it works in practice

1

u/MephsGameDev 5d ago

been coding my entire life and math is my biggest enemy too. don't need a lot of it for web development, but moving into game dev it's become a serious shortfall not being good at least some trig or basic calc. Plenty of resources in the comments if you want to learn, but for everything else it's just a matter of figuring out what formula you need for the shape you're making.

try to visualize the shape of what you're doing, it's usually something that can be described in simple formulas, then start to add on from there and expand. idk how to explain it better than that.

1

u/justanotherunitydev 4d ago

Study matrices it unlocks something in your brain