Hey guys, I have a script that on a button S(ave) press saves a given object’s position, rotation, velocity and angular velocity.
Then another button R(estore) assigns them back so the object goes back to the same position/rotation/velocity/angular velocity that it had during Save.
The only problem is, that with more complex bodies - such as with a ragdoll, on each restore, the ragdoll behaves different, I wonder what the hell is wrong with my script.
which is basically:
var trPosition:Vector3;
var quatRotation:Quaternion;
var velocity:Vector3;
var angVelocity:Vector3;
function Savee(){
trPosition = transform.position;
quatRotation = transform.rotation;
velocity = rigidbody.velocity;
angVelocity = rigidbody.angularVelocity;
}
function Restoree(){
transform.position = trPosition;
transform.rotation = quatRotation;
rigidbody.velocity = velocity;
rigidbody.angularVelocity = angVelocity;
}
P.S. it shouldn’t be relevant to the problem but here is the script that calls it:
basically every object that will need saving like that, has the script above, and there’s one “ultraparent” who uses the script to call Save(e)s and Restore(e)s:
var ultraParent:Transform; //a parent of anything that needs to be saved and restored
function Update () {
if(Input.GetKeyDown(KeyCode.S)){
for(var child in ultraParent){
var temp = child.GetComponent(Snapshot);
if(temp)
temp.Savee();
}
}
if(Input.GetKeyDown(KeyCode.R)){
for(var child in ultraParent){
temp = child.GetComponent(Snapshot);
if(temp)
temp.Restoree();
}
}
}