What could I have missed?

When Rick challenged us to build the ladder and climbing mechanic I understood that much of what we’d done so far could be reused to make it work.

I was so proud that I spotted which parts I should copy/paste and set up the script in the same order as Rick. But when I tried it, my character just flew away as if he was climbing right from when I pressed Play.

After a lot of experimenting, I ended up deleting everything and went on to follow him and then it worked without any issues. Since I can’t figure out what I did wrong, if anyone else had these issues or recognize it, what could I have done wrong?

I even wrote this statement by myself, which feels like what should have been the issue:

if (!myBoxCollider.IsTouchingLayers(LayerMask.GetMask(“Climbing”)))
{
return;
}

The only things I know I didn’t follow were:

  • Using a BoxCollider2D instead of a CompositeCollider2D for the Climbing tilemap
  • Forgot to add a TilemapCollider2D
  • Didn’t adjust the ladder’s custom physics shape

Hi Nukem,

There are multiple potential reasons for a player flying away. The most common one in this game is a non-trigger collider. If the player is inside such a collider, the physics simulation tries to push him out. That could look as if the player were flying away.

if (!myBoxCollider.IsTouchingLayers(LayerMask.GetMask(“Climbing”)))
{
    return;
}

does not do anything expect terminating the method if the if-condition is true.

Thirdly, if there are no restrictions, the code for climbing gets executed. If there are no “rules”, the player will always climb, even if there is no user input.

As you can hopefully see, this is a lot guess work. Without seeing everything you did, there is no way for me to know what might have gone wrong in your case.

I hope this helped anyway. :slight_smile:


See also:

Privacy & Terms