Consider the following: I have a cube, which has a function called Freeze. It sets the cube rigidbody to kinematic, and when called again, it unfreezes said cube. I was trying to implement a way for the cube, after being “unfrozen”, re-adding it’s speed from BEFORE it was frozen, to give and idea of it being frozen in space-time. However, the code I wrote does not work. Is there a way to do this?
Code I used (C#):
void Freeze() {
if (isSelected) {
if (!rb.isKinematic) {
retainedSpeed = rb.velocity;
print (retainedSpeed);
rb.isKinematic = true;
cubeMesh.materials [1].SetColor("_EmissionColor", freezeColor);
} else if (rb.isKinematic) {
rb.isKinematic = false;
rb.AddForce (retainedSpeed);
cubeMesh.materials [1].SetColor ("_EmissionColor", defaultColor);
}
}
}