3 ms·
Physics simulation is really interesting. I had the fortune of working on a physics simulation engine in industry (although the company culture was dysfunctiona
by klodolph 6y ago
Physics simulation is really interesting. I had the fortune of working on a physics simulation engine in industry (although the company culture was dysfunctional, that’s another story), and I often hand-roll my physics simulation code in games that I make as a hobby, or use off the shelf engines like Unity’s or P2.
The timestep naturally has to be small enough that you can get good results with values that change quickly. The simulator I worked on professionally used adaptive step size. For these applications where accuracy is paramount, the adaptive step size gets you there with a smaller computational budget. For games, you often want a very repeatable physics simulation. For example, if the player can normally jump onto a 3.5m ledge, and the step size changes, maybe the player can now jump 3.6m, or maybe only 3.4m. This can frustrate the player (or it can be exploited in speedruns).
I’d also say that for most games, physical accuracy is very rarely a useful tool. That’s just my experience. 90% of the time, I just want velocity, momentum, and collisions. If you are using an existing engine like Unity, this means, among other things, that you probably don’t want to make everything in your game a Rigidbody. The physics simulator is great for things like knocking crates over and making characters ragdoll, but for your characters in-game, try doing the physics yourself in a custom character behavior instead of using Rigidbody.
You might be surprised that a ton of examples from the Unity site are like done like this.
- thedirt0115 6y agoThere's a billiards simulator/game[1] that uses event prediction instead of step-based physics for realistic and reproducible results. It solves the equations of motion to find the next event, animates to that point, and continues until nothing is moving. This is feasible since there are only 16 balls and 1 cue tip, but I imagine that as computational power continues to increase, the scale of such simulations will increase too. I'm excited to see what's next :) [1] - I read a paper that specifically talked about step-based vs event-prediction for billiards simulation, but I can't find it now :/ Virtual Pool 4 might use the system for its physics, but don't quote me on that! P.S. - Unity has a pretty handy built-in CharacterController class that lets you move around while respecting collisions -- you just need to add your own Gravity. Also, for more advanced character movement, Catlike Coding has a great series of tutorials: https://catlikecoding.com/unity/tutorials/movement/ https://catlikecoding.com/unity/tutorials/movement/
- klodolph 6y agoThat’s sort of the way things are done in industry. One strong example is in mixed-signal electronic simulation. Your digital portion of the system describes digital outputs in terms of digital inputs and gate delays, more or less. Changing the digital inputs results in a queue of events. So you run the analog portion of the system until the pending digital event, process the digital event, and then continue the analog simulation.