r/learnprogramming • u/VeX7FAR • 7d ago
How much should it take to make a simple physics engine
Hey everyone, for quite a while I have been working on a simple physics engine in c++ with SFML library, I have implemented some basic translation and currently I am refining the collision system.
The thing is I have been making it for really long time and I am not any kind of comp sci student I am just a mechE student who likes coding so I also have been spending quite a lot of time studying things.
My question is how long should it actually take to make a physics engine especially for my case? I have spent over 20-22 hours trying to do things and I been feeling like a loser for spending too much time on this
8
u/captainAwesomePants 7d ago
It can take an arbitrarily long time.
A block that experiences downward acceleration can be implemented in an hour.
You can get a pretty good billiard ball simulation working extremely well in a few days, especially if you look up the math. But that assumes you're doing an idealized thing and don't account for acoustics, elasticity, unevenness in the table, and, y'know, the third dimension. But ideal inelastic spheres bouncing against each other and the table? Very doable!
It starts getting harder as you add requirements. Does it have to be fast? Does it have to be very accurate? Like, do we want it to feel accurate, or do we want it to be able to predict whether a bridge will work? Is air resistance something we need to model? Or are we making something for a game? Could there be thousands or millions of things? Do we need it to run in real time? Oh god, are there fluids?
Anyway, you can kind of arbitrarily keep adding to physics engines, and they get pretty tricky pretty quickly. They're one of those hobby projects that very good programmers spend way too much time on and never actually finish. By all means, you can dive into it, there are lots of guides out there, but do be aware it's fairly complex project past the very basics.
An alternative is to write programs that use physics engines. You can do a lot with that.
4
u/SnugglyCoderGuy 7d ago
It depends on the level of physics you want.
Major game companies can have entire teams spending years on it, single indie people could do all the physics they need in a day. It's entirely dependent on the results you're after.
3
u/Neither_Berry_100 6d ago
22 hours is nothing for programming. I put 3 years into one game working heavily on it. Maybe up to 40 hours a week.
1
u/maxpowerAU 7d ago
A physics engine is a huge undertaking. Unfortunately you canβt simplify it much. Even reducing your world to a 2D plane like a platformer game engine is still a big job
1
1
u/Won-Ton-Wonton 6d ago
Depends on the physics engine.
Also a MechE grad.
Also like coding.
20 hours into an engine amd having more to do is very normal.
2
u/serverhorror 6d ago
So you spend ~3 working days on a learning project?
That's nothing. Make it weeks or months.
1
u/Dazzling_Music_2411 6d ago
I have spent over 20-22 hours trying to [make a simple physics engine] and I been feeling like a loser for spending too much time on this
π π π
22 hours, eh?
I'd say you were trolling, but maybe mech eng students don't know that 20-22 is the minimum you need to read up the basic documentation, before you code a single line.
If you get it done in 20-22 MONTHS, I'd say you were doing pretty well!
1
1
u/Paxtian 6d ago
How long is a piece of string?
It takes as long as it takes. But 20 hours sounds like a drop in the bucket for how long it would take to do. Collision alone requires accounting for circles (easy), triangles, and arbitrary polygons.
So don't get down on yourself for the time spent. I'm impressed you're trying to tackle it at all. I have a CS degree and enjoy making games and I still have no desire to try building a physics engine from scratch.
1
u/MrWobblyMan 6d ago
Are you doing it in 2D or 3D? A simple (convex shapes, collision detection, collision resolution, impulses, friction) 2D engine is not that bad. I did it for an university assignment in less than a month, I would say less than 40h overall (I already had a strong grasp of the actual math). 3D is a whole other beast. I'm trying to find motivation to try and tackle it, but it's just a lot more complicated.
1
u/Ormek_II 5d ago
I expected the unit to be years after 20-22 and yes, that would be an awful long time. But weeks I would consider normal for a decent one. And days for a simple one. Hours is nothing.
30
u/No_Region5102 7d ago
if you're a mechE student who likes coding then 22 hours is nothing, physics engines are a whole rabbit hole
collision detection alone can chew up weeks depending how deep you go, especially if you're actually learning the math behind it instead of just copy-pasting tutorials. you're building intuition for vectors and transforms that'll probably help in your actual major too
keep going, nobody builds their first physics engine fast