- Home /
Can I run a duplicate physical world at high speed?
I am writing a game where the player throws an object at a group of other objects. The result is chaotic. I was wondering if it was possible to simulate what will happen, before the object is thrown?
Ideally I'd like to duplicate the physical 'world', set the Time.timeScale to a large number so that this duplicate world runs very quickly. Having run the duplicate world for a given time I can then see what the effects were, which are what the effects would be in the original world if it continued running in its current state.
The game is not performance critical.
Is this a ridiculous idea? Or feasible?
You may be able to get a reasonable result by duplicating your rigidbodies on a much smaller scale (say 1/1000) somewhere hidden to the camera. The relative speed will be 1000x due to the smaller scale. Things to be aware of: it won't be a perfect 1:1 simulation, collisions may be an issue (you can force continuous collisions for all micro-dupes but it's not exactly the same), physics sleep and maxAngularVelocity values should be set on each dupe rigidbody to 1/1000 of the current physics settings, Time.fixedDeltaTime (physics update rate) should be set as low as possible.
Alternatively use 1:1 scale for the duplicate world but increase the speed of everything to say 1000x. This creates an additional issue in that non-linear physics calculations (such as drag) with respect to speed won't be correct.
Interesting ideas, thanks! Is it possible to have 2 worlds running, with different timeScales? I would ideally like the original world to stay at a timeScale of 1
The physics engine in Unity is not deter$$anonymous$$istic. Sift through the answers in this thread and notice, in particular, the comment about players sometimes shooting dead enemies locally, but empty air on other machines, because the Source engine does ragdoll physics locally. This is because the physics engine utilized by Source, like Unity's, isn't deter$$anonymous$$istic, so when the same event is run multiple times (in multiple different clients, in this example's case), then differences like that occur.
Your idea of running a separate copy of the world would suffer exactly the same differences. If you're careful, and the results you're trying to predict are defined roughly enough, then it'll probably work most of the time. But sooner or later, you will come across some situation where it didn't work out, and your copy-world didn't match the actual result.
I don't believe it's possible as Unity has a single Physics and Time system which applies to everything in-game. $$anonymous$$any of the physics settings can be overridden on a per-object basis but the fixed update time will be the same. I expect it would be a huge job trying to work around this, if it's even possible.
$$anonymous$$y suggestion would leave the original world at a time scale of 1, but you would need to run the fixed update very fast so that the small scale duplicate world physics are more accurate.
Another idea:
Save the state of your world
Use an alternate camera to fade out the current view (or render the current view to texture and just display that few seconds)... basically just don;t show the real word for a bit
Bump the Time.timeScale to 100x or whatever speedup you need, and set the target frame rate really low
Wait for results, saving what info you need (object positions, saved render images from a non-visible camera etc)
Restore the time scale and world objects to original values, restore the camera, then show the results
This has the advantage that you are using the actual world objects, scale, and physics that you are simulating.
If you simply want to know the outcome without the intention of altering it, this will fit:
Perform the deed in real scale, where the main camera didn't see it.
Record the whole chain reaction of involved rigidbodies.
At the end, you know what happen.
Playback the recorded data where the camera can see it, just like it has not happened before.
You will have to suffer some kind of lag though.
Your answer
Follow this Question
Related Questions
Help with orbits 1 Answer
Simulating the graphics of a rolling 3D ball in a 2D game 2 Answers
What would be the best approach to implement a conveyor belt? 0 Answers
cloth simualtion problem 0 Answers
simulating real world camera in unity 0 Answers