Pshysics.CapsuleCast() vs Collider component

Hi! I’m following Code Monkey’s Unity course for begginers/intermediates and there he separates the logic from the visuals for the player by creating an empty game object as the parent and putting the player visuals as the child. Therefore, the parent contains all the scripts, including the code for the player’s movement. To detect collisions he uses Physics.CapsuleCast() and allow the movement only when no collisions are detected, obviously. He also uses this method for interaction with other objects.

So my question is:

Why use Physics.CapsuleCast() (or any other shape cast) to detect collisions for movement and interactions instead of attaching a Collider component to the parent game object (and adjusting it’s size to the visuals)? That way the player would collide with other objects by default and the interactions could be handled inside a OnCollisionEnter() or OnTriggerEnter().

Is is something related to performance? How do I know when to use one or the other?

Yep, the way he did it is actually very unreliable for most games, but it works for his Kitchen game, because:

  1. The Kitchen material is not moving.
  2. By doing any kind of physics cast returns information about the object you’re colliding with, so it serves as collision AND a way to identify what you have collided with, in his game that’s necessary because you can interact with things you’re colliding with.

But aside from that specific game it’s better to do a Capsule collider on the parent object.

Using shape casts like Physics.CapsuleCast() is helpful when you need more precise collision detection than what a simple Collider provides. This precision is useful for things like checking if a character can fit through a narrow space or if a projectile can hit a target behind obstacles. However, shape casts can be more computationally expensive than simple Collider-based detection, so it’s important to consider performance when deciding which to use. In general, if you need precise control over collisions or have complex shapes involved, shape casts are a good choice. If performance is a concern and simpler collisions are sufficient, stick with Collider-based detection.