I have written a lidder climbing script that works fine (uses interfaces and triggers), except for when it comes to climbing through platforms whilst on a ladder.
Basically, I want to be able to climb up a ladder and then pass through the platform and move onto the top of it. That’s easy. Just set the player’s collider2D.isTrigger to true. (Refer to figure 1 for correct non-collision) Here is the code I am using
Then the problem is coming back down the ladder. I pass straight through the platform at the bottom of the ladder and move/fall through it. (Refer to figure 2 for incorrect non-collision)
I think instead of changing the player’s collision, you should change the platform’s. You could know to only change the collider for the platform if the ladder is overlapping it. Since in the top picture, the ladder is overlapping the platform, the player would be able to get through, but in the bottom picture, the ladder isn’t overlapping the bottom platform, so the player would stand on that platform fine.
Depending on the type of game, enemies may still want to stand on those platforms, so instead of disabling the platform’s collision altogether, in the long run it is probably better to use Physics2D.IngoreCollision to just cancel the collision between the player and the platform and reenable it afterward.
I expect the ladder would also need another trigger just above the platform, to tell the script not to cancel the collision straight away, just to cancel the collision anytime the player wants to come down the ladder.
Using two different types of platform layer (solid, pass through) would solve this problem. When your player is on the ladder let it pass through the “pass through” layer.