Something to do with isKinematic

I’m kind of new to the scripting in Unity, but I just want to try something out while I am still learning.

After a projectile is thrown toward a wall of unconnected blocks. I want the blocks to freeze in space after a specified time after collision. Then maybe a few seconds later, everything goes back to normal and the blocks drop.

Any help is greatly appreciated.

Here is the short and simple code I am currently fiddling with. The same code format for the time part works perfectly fine for creating a new object (projectile).

var delay = 2.0;
private var freeze = 0.0;
function OnCollisionEnter(collision : Collision) {
		if (collision.relativeVelocity.magnitude > 10  Time.time > freeze) {
				freeze = Time.time + delay;
				rigidbody.isKinematic = true;
		}
}

If I’m doing something horribly wrong can somebody please tell me?

Hi, welcome to the forum!

Is the problem that the blocks are freezing, but then not moving again after you reactivate them? Generally, a rigidbody goes to “sleep” when it is set to kinematic and has to be woken for physics to resume. You can use the rigidbody.WakeUp function to do this.

Another approach to this might be to set Time.timeScale to zero in order to freeze the action in the game, and then set it back to one to resume. However, this will freeze all objects in the game rather than specific ones you choose.

Thanks for the tip, but the current problem at the moment is that the blocks pretty much ignore the time frame I give it. So it will freeze instantly no matter what I do.

OnCollisionEnter can be a coroutine, so you can simply yield WaitForSeconds in the function:-

var delay: float;

function OnCollisionEnter(collision : Collision) { 
    yield WaitForSeconds(delay);
    rigidbody.isKinematic = true;  
}

It worked! Thank you so much, I knew there had to be a code like that somewhere but I was looking in the wrong place.