Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fall through one-way platforms? #29

Closed
AniMittra opened this issue Sep 29, 2014 · 2 comments
Closed

fall through one-way platforms? #29

AniMittra opened this issue Sep 29, 2014 · 2 comments

Comments

@AniMittra
Copy link

I'm trying to have it so my character can drop down through one way platforms by pressing the down arrow key. Many games with one-way platforms let you do this such as Mario, Kirby, Smash Bros, etc.

I was able to get the conditional working to see if I was standing on something in the "OneWayPlatform" layer, but I can't figure out how to get my character to fall through it. I tried both IgnoreCollision and IgnoreLayerCollision and neither seemed to do anything. My guess is that this has something to do with the layer mask inside the CharacterController2D script, but I have no idea how that works. I am stumped!

If anyone could explain to me how to do this or point me in the right direction that'd be great!

@KellyThomas
Copy link

I was looking at this issue a little while back. The solution I opted for was to add a little functionality to partial class. This way I would be able to incorporate any updates to the core CharacterController2D while avoiding most merge/update issues.

The process I used was:

  1. Store existing LayerMasks
  2. Manipulate LayerMasks when enabling/disabling OneWayPlatforms

Then I set OneWayPlatformsActive = false when the down key is pressed, and OneWayPlatformsActive = true when the key is released.

The code is available in gist here.

@AniMittra
Copy link
Author

Oh man thank you so much, I just implemented it and it seems to work! I would've never figured it out without you. I was reading up on the "|" and "&" operators and bitwise stuff to try and work with layer masks but It's much simpler than I thought. I've also never used a partial class before so you taught me something new, brilliant!

I'm truly grateful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants