Hello,
I’m wondering if I could start my game from a point in time after the physics engine has moved my game objects a bit.
I have many blocks that roll down a hill, and I want the game to start when the blocks are at the bottom of the hill, so the player doesn’t have to watch them actually roll. I think I have to write down the position/rotations of all the blocks, and then manually move them there after stopping the play test. This can get quite tedious with many blocks. Is there a better way to do this?
It’s basically saving the scene as it is after the physics engine has done its part moving the objects.
1 Answer
1
Using physics to place stuff is a feature sadly missing from Unity. I had such a feature in HeroEngine because it was so useful.
However there are tools in the Asset Store that let you maintain stuff that happens during play. For example, Editor++ comes to mind. Using that plugin you can then select all the cubes and have it remember their transform during play. Then stop and apply what was remembered and they’ll be in their settled (at the bottom of the hill) location.
This is far easier than doing it manually with pencil and paper. But if you don’t want to use a 3rd party component like that, you could write a script that on some input (say a button press) records all the important transform info from the objects you are interested in to a file. If you give them a unique name, then it would also be straightforward to read that file back in with yet another script (editmode this time) and apply the updated transforms back to said objects.
I'm trying to avoid the physics engine from calculating it all at runtime, because at the moment it's lagging the game. When the blocks stop moving the lag settles, so that's why I want it the game to just start there. There is no way to just "save" the scene as it is at that certain point in time?
– PolinatorTotally out of the blue, but maybe it works. Start your scene and pause it at the right time. Don't stop it, just pause. Then save the scene. No idea if this actually works.
– LockstepNo, sadly that doesn't work. I've tried before asking, heh. That would make it too easy!
– PolinatorMake the variables static? shrugs
– GC1983I'm sorry, I don't understand what you mean by that. What variables are you referring to make them static?
– Polinator