Comment by andai
2 days ago
I have the opposite problem[0], one of the first programs I wrote as a child was bouncing ball sim. I didn't get the math behind it, I just fiddled with the code until it seemed right.
It's only a few lines of code, and it's still my "hello world" for any interactive programming system or gamedev library.
Make the ball respond to keyboard ... that's velocity! But it's too jerky, so we wanna smooth it out... that's acceleration! Make it fall, that's gravity! (Constant acceleration in one direction.) Ball keeps moving endlessly is weird, let's make it slow down a tiny bit each frame... hey look, that's friction!
The next year in school we learned the math for most of the same stuff (velocity, acceleration, gravity, friction) and it was pretty straightforward to me (even though I still suck at math) because I already had the "instantaneous" (frame by frame) model built up from making it in code, so I could sorta-kinda translate that to the continuous (formula-based) perspective.
I made a cloth thingy like this a few years ago after watching a video about it. The actual cloth sim code is like, 3 lines iirc.
It basically just jiggles the system a few times based on stuff being too close or too far away. So the idea is that the movement of one part transfers to all the others.
I'm a bit confused now since I saw some that have hard limits on the segment length (e.g. chain sims), whereas this one seems to be more stretchy (spring based?)
The neat thing about this stuff is that if you aren't going for physical accuracy (or efficiency), you can half-ass it by just guessing and fiddling with the code or the math. E.g. I still don't get how springs actually work, but my own terrible guess works well enough to be amusing!
[0] Whereas after repeated attempts over decades, web never really clicked for me. Well, it did when PHP was popular... I can still make stuff with PHP and vanilla JS, hahaha.
Yeah I went through a similar process as a kid. I remember learning trigonometry in high school and realising I was way ahead because I'd been using sin and cos to calculate positions of 2d spaceships for years...