Freeze position in 2D?

Hi, Im doing a platformer game and I need freeze position of character when he touches something.

I saw rigidbody.constraints but is only for 3D, some ideas?

Thanks

hi @07Mr07 use this.

gameObject.GetComponent<Rigidbody2D>().isKinematic = true;

and

    gameObject.GetComponent<Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezePositionY | RigidbodyConstraints2D.FreezeRotationZ;

you can go for both methods. thanks

Attach Collider2D & rigidbody2d in that object, & set velocity + gravity to 0, when it collides…

enter code here

function OnCollisionEnter2D(coll:Collision2D)
{
	rigidbody2D.velocity.x=0;
	rigidbody2D.velocity.y=0;
	rigidbody2D.gravityScale=0.0;
}

@07Mr07
For the positions:

rigid.constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezePositionY;

For rotation:

Rigidbody2D.constraints = RigidbodyConstraints2D.FreezeRotationZ;

For both:

rigid.constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezePositionY | RigidbodyConstraints2D.FreezeRotationZ;

PS. code is not tested.

You can just set Time.timeScale to 0 if your movement is basen on delta time then return it back to 1 to move the player again