Scripting Collision tutorial explanation

Hi all,

I just did the 2D collision tutorial (Recorded Video Session: 2D Platformer Character Controller - Unity Learn) and I had some questions.

I don’t like not understanding why I am doing something, so here goes:

  1. Why do we need a “shell”? I know it’s to offset the collider when detecting a collision, but why? Can’t the collider just sit directly on the other collider? I tried that in my code (getting right of the shell) and the object sits for the fraction of a second then falls through the ground.

  2. Why is there a minimum move distance? Does it matter?

Thank you

I didn’t watch the whole tutorial but just at first glance I think I know what you’re talking about.

Basically if your object’s collider is overlapping another collider even a little bit, the shape cast won’t detect that collider in the next check. So the shell is there to provide a safety buffer, ensuring that your casts always work properly and detect nearby colliders every time.

That also explains the behavior you’re seeing. The first check works, and moves the object edge-to-edge with the other collider. Mix in some gravity and other random floating point errors, and your collider was probably overlapping the ground. Then in the next check, the cast sees nothing and your object falls.

“Minimum move distance” is useful so that if an object moves .000001 units you don’t need to recalculate and correct with physics. You only consider a “move” if it’s a significant enough amount to require an update. It’s mostly for optimization reasons I believe.

1 Like

That makes a lot of sense, thank you. It does explain the behavior and it’s something I will have to keep in mind.

Great explanation, thanks! So I guess something like a minimum distance of 0.01f would be more than enough?

Yes, that may even be too large depending on your game!

Perfect, thanks again! That was a real eye opener! :slight_smile: