Freezing an object and keeping it's velocity
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);
}
}
}
Answer by jdean300 · Aug 19, 2016 at 10:30 AM
Force and velocity are two different things - what you're going to want to do is replace rb.AddForce (retainedSpeed);
with rb.velocity = retainedSpeed;
Force causes acceleration, which changes velocity OVER TIME whereas setting the velocity directly changes velocity instantly.
Thank you for the answer! Now everything is working correctly!
Your answer
Follow this Question
Related Questions
Rigidbody is colliding terrain on isKinematic = false. call although meshes don't touch 0 Answers
How to make Airplane move forward faster INSTANTANEOUSLY? 1 Answer
How to check if kinematic rigidbody is overlapping anything in the scene? 0 Answers
Kinematic sphere doesn't move 1 Answer
Stuttering with moving Rigidbody 1 Answer