- Home /
2D Ladder Climb Through Platforms
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)
Figure 1:
Figure 2:
Thanks Unity community, Kwibble
you could have a bool the tracks if you are moving up or down, and in you collision detection add it to the if-case.
you could for example change the bool according to the difference in the transforms Y-coordinate between the frames.
feel free to post some actual code if needed =)
Another possible way is to have a collider that blocks each of the ladder holes(you would have to make a hole, collider gap, in the platforms). If you are climbing on the ladder then the these colliders are disabled for that ladder, if you are not climbing on that particular ladder then that ladders hole block colliders are enabled. With all your other platform colliders enabled all of the time to stop the fall through like in pic 2(that platform would not have a hole cut in it's collider setup).
@Taxen0 Ah, updated with a link to the code - sorry about that
@$$anonymous$$rSoad Wouldn't that lead to horrible movement because the character would lurch around everywhere?
I think the main problem is the fact that I am using triggers on the ladders. This means when any part of the player enters the ladder's area, he can be climbing the ladder.
No it should not affect movement in any way at all... It may not be the best way of doing this... It was just a quick idea :)
Answer by Ferb · Feb 04, 2015 at 10:50 AM
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.
Answer by hawken · Nov 09, 2015 at 01:03 PM
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.
Your answer
Follow this Question
Related Questions
How to detect CompositeCollider2D shape center? 0 Answers
Unity2D - Creating multiple Ladders that centers the player? 1 Answer
Physics2D checking if object goes out of OverlapArea 1 Answer
climb speed changes drastically when game window is not maximized 1 Answer
2d Ladders snap to middle? 1 Answer