How to change object's rigidbody during runtime?

Hello! I am attempting to code it so that when my player collides with a shape (triangle, square, circle, etc.), the player’s sprite and actual COLLIDER (rigidbody) shape changes. Changing its sprite is easy enough, but how do I make it so my player inherits the rigidbody (and thus collision shape) of another object? Is this possible WITHOUT creating another object?

Thank you!

not sure but how many shape collider you need? if small can do manually

Actually just 3! Just the triangle square and circle.

You could add all three colliders to the gameobject but disable two of them. Then when you collide with the other object disable the currently enabled collider then enable one of the other colliders on the gameobject

for example

BoxCollider2D mBCollider;
CapsuleCollider2D mCCollider;
CircleCollider2D mCircleCollider;

void Start {
mBCollider = GetComponent();
mCCollider = GetComponent();
mCircleCollider = GetComponent();
}

void EnableCollider(int id)
{
if(id==0) { mBCollider.enabled = true; mCCollider.enabled = true; mCircleCollider.enabled = true; }
else if(id==1) { mBCollider.enabled = false; mCCollider.enabled = true; mCircleCollider.enabled =false;}
else if(id==2) {mBCollider.enabled = false; mCCollider.enabled = false; mCircleCollider.enabled = true; }
}

then just call EnableCollider() to enable it on collision or something

for example to enable CircleCollider you do → EnableCollider(1)

1 Like

Thanks much! I did not know you could add multiple colliders to the same object. You helped a lot. +1!