Jump when touching the ground challenge - RigidBody2D vs. CapsuleCollider2D

Hi, so when I attempted the challenge to stop the player from multi-jumping (i.e. only jumping when the player is first touching the ground), I used my RigidBody2D object to check if the player was touching the Ground Layer (which worked for me):

However, when Rick went over his solution, he used the CapsuleCollider2D to make this check. I tested and this works for me as well:

My question is: Does it make a difference whether I use one solution over the other? Is it better practice to use the CapsuleCollider2D? And if so, why?

1 Like

Hi,

The Rigidbody2D acts as a compound collider whose shape matches the shape of all colliders attached to this game object and its children. If you just want to check if a specific collider is touching a layer, you must call the IsTouchingLayers method on the collider. If it does not matter or if you want to to check if the compound collider is touching a layer, you call the method on the rigidbody.

Use the version which solves the problem for you. If both solutions solve it, use the one you prefer.

Did this answer your question?


See also:

2 Likes

Yes that does, thank you!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms