I’m trying to find ut how to manually advance physics simulation. I need this so I can show “preview” of path that will object travel after force is applied to it. Haven’t found anything here on forum or on google. Is this possible at all?
Physx isn’t deterministic so it can’t be stepped through. But you could probably pause the simulation and move ahead by setting Unity - Scripting API: Time.timeScale to 0, then setting to 1 each time you wish to move forwards.
In theory this means if you increase it, it should simulate faster. But for this to work correctly, you would probably need to change how often fixedupdate runs as well. I am only shooting in the dark here.
Thanks a lot for your reply! I have now a solution and a way around my problem, I’ll just calculate the “preview” trajectory of the object until first collision and then also simulate physics of the object myself until that point. After the contact I’ll just switch to physx and let it sort out all the other collisions and movement.
What you can do is launch an invisible physics object, record its transforms, then draw the line showing the preview, then fire your visible physics object.
Yeah, that would work but the problem is it would not be instant. The prediction trajectory would take some time to show (time it takes for the invisible object to move). This would be a big problem if you want to do dynamic trajectory prediction based on parameter that the user is dynamically changing. Thanks for your thoughts anyway, much appreciated!