TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Stacking forces in a physics engine C++

3 pointsby leakbangover 2 years ago
So for a game that I&#x27;m working on I have looked at a lot of the widely used and widely praised physics engines (Havoc, Bullet, PhysX, Jolt, Newton Dynamics, ...) to implement in my game but after reviewing each one of them I came to the conclusion that it is best if I create my own physics resolver.<p>The aforementioned physics engines failed basic physics tests or had very complex code bases to the point that I think this route will be easier. I did notice that many of these engines especially PhysX and Bullet do a lot of tricks to correct their simulations. I assume one reason that they include such tricks is to optimize for performance on a wide range of hardware.<p>So I think it couldn&#x27;t be that hard to write a simple (rigidbody) physics resolver that is only designed to run in a single thread on X86 based processors. And also I don&#x27;t think I need to mess around with too many optimizations since the levels in my game are pretty small, so I might just be able to get away with it. I never dabbled too much into the nuts and bolts of a physics engine so I am quite unsure about certain things could be done.<p>For instance let&#x27;s assume a simple case. I have a digital scale and I want to measure the weight of whatever&#x27;s on top of it. So the way I would like to do it is to simply measure the amount of force that is being applied to the surface of the scale and display that. That way, when 2 objects are stacked on top of each other, it shows the correct stacked weight. Or if there is another object like a press, pushing towards the surface of the scale, then it also would show the force that the press is applying.<p>I don&#x27;t know how to implement a system like this. Do you know of a cool way of achieving a system like this? Also if you have any tips or cool resources for physics simulations, I&#x27;d appreciate them!

3 comments

jmiskovicover 2 years ago
Your example with two stacked objects on the digital scale demonstrates force&#x2F;impulse propagation. The middle object should sense incoming forces and then propagate them onward to other touching objects. If you want to evaluate existing rigid body physics engines, you could examine their implementation of Newton&#x27;s cradle. In the cradle each ball needs to propagate the received impulse to the last ball it without the ball being moved at all. I&#x27;ve worked with open-source ODE engine and it doesn&#x27;t do the impulse propagation so you would need a small air gap between balls to transfer the momentum.<p>That&#x27;s for theory side. From engineering viewpoint the desire to create from scratch is always strong and most often regretted later. One thing you may not expect, for physics engine to detect and resolve collisions between various shape types (sphere, box, cylinder...), each combination of shapes needs to be implemented separately. This is a lot of code riddled with edge cases just for that feature. Maybe dig through a few papers that describe implementations before starting your own.
评论 #33444894 未加载
369548684892826over 2 years ago
From personal experience, if you write the physics engine yourself you might find you never get around to making the game itself.<p>If your game loop is running at 60 fps then each frame exists for about 0.017 seconds. What happens if you have a 10 Kg weight sitting on your scale for the duration of half a frame (0.008 seconds), will your engine display 5 Kg on the scale, or what?<p>Interesting problems to solve, but can easily take up all your game development time.
Simulacrum0over 2 years ago
i wish you well on rolling your own Physics. Its certainly straightfoward to implement formulas for kinematics&#x2F;dynamics as you suggest, but like the first comment references, timesteps and stability are quite elusive to get manageable for varying amounts of moving objects. While stacking might be an isolated case, i could definitely see the scope expanding beyond initial estimates for &#x27;final tuning&#x27;. Bullet does a good job w&#x2F; stacked cubes and i&#x27;d expect PhysX to be equally proficient.