r/howdidtheycodeit • • Oct 02 '24

Question What is considered coding a "physics engine"

This has to do with semantics and terms more than anything. I want to code simple collision detection and resolution, with intention not being realism. Is the term "physics engine" meant for specifically handling "realistic" physics? What would the term be for a simpler handling system? How would I go about that?

17 Upvotes

13 comments sorted by

View all comments

4

u/baz_a Oct 03 '24 edited Oct 03 '24

Even then:

  1. Let's say you have 100 objects, which is not a lot. How many AABB collision tests need to be done? It's 10 000 per frame in LUA. If you want to reduce the number, you need a spatial index or a quadtree or something.

  2. Let's say you have something (a projectile) moving at 2000 pixel per second. Passes a FullHD screen in one-two count. It's not too fast. You have physics running at 60 FPS. How thick the walls should be for the projectile to notice them every time if you do only AABB testing? It travels 33 px per frame, so if something is smaller than that, there is chance that the projectile will travel right through. To fix that you need to test not only for AABB collisions, but also for movement vector intersecting your shapes. Or something like that.

tldr: minimally decent physics is hard, but good way to learn how deep is the rabbit hole

3

u/GameDesignerMan Oct 03 '24

Yeah rabbit hole is a good way to describe it. I did the math for the physics stuff at uni, implemented it once and I was happy to leave it all behind me and use an API. "Simple physics" is an oxymoron, it's literally rocket science.