- Home /
how should I save rigidbody's properties if I want to freeze it in time (just this object) for a moment
I want to freeze a rigidbody, and then bring it to"life" again, the code, simplified goes like this:
var velocitySave:Vector3; var angularVelocitySave:Vector3; var paused= false; function Update () { if(Input.GetKeyDown(KeyCode.Space)){ if(!paused){
paused= true;
velocitySave = rigidbody.velocity;
angularVelocitySave = rigidbody.angularVelocity;
rigidbody.Sleep();
}
else if(paused){
rigidbody.WakeUp();
rigidbody.velocity = velocitySave;
rigidbody.angularVelocity=angularVelocitySave;
}
}
}
The thing is, I really need this rigidbody to behave the same everytime, and from what I can see (in the more complex scene where there's around 10 objects that need to freeze, bounded by joints) they don't always behave the same when their rigidbody settings (velocity and angular velocity) are restored.
I assume the problem is that I need to save (and restore) velocity and angular velocity not in the Update function, but in the Fixed Update. but switching update to fixed update didn't seem to help me. the objects still seem to recieve slightly different velocities at times, when I'm testing them.
What should I do? improve physics solver count? do move it to fixed update but in some specific way? any ideas? I should probably move it to fixed update anyway, shouldn't I.