Locking a physics object's position once it reaches a specific point C#

Is there a way to make an object lock its position once it reaches a specific point? For example, when it collides with another object? I’m trying to make a puzzle game and I am trying to figure out how to make a push block puzzle, I’ve gotten the push block to move to the position I want it to be in once it collides with the end goal, but I can’t figure out how to lock its position from there. I am using the C# coding language

An easy way to lock the position of a GameObject would be using the “FreezePosition” RigidBody constraint.

Add a RigidBody component to your push block; then, when it collides with the end goal, you can apply “RigidbodyConstraints.FreezePosition” to the constraints property on the RigidBody.
You may want to explore more types of RigidbodyConstraints if the game object still rotates.

Here are a few more references from the Unity Docs to help get you started:

Thanks for the info!

1 Like

Constraints work but know that the physics system has to calculate constraints so if you want to stop any collision response and have zero overhead then set the Rigidbody2D body-type to Static.

Indeed, if you set all the Rigidbody2D constraints, you should see this info in the Inspector.