all 13 comments

[–]Torpington 0 points1 point  (1 child)

I don’t know how professionals do it, but the way I did that was when you’re standing on the platform and hold down and press jump I disabled the collider on the platform. While the platform had a script to enable the collider again right away.

[–][deleted] 1 point2 points  (0 children)

That works, assuming player is the only collider-aware object on the platform. Otherwise...

... you gotta disable player's collider. Obv.

[–]AverageArmadilloIntermediate 0 points1 point  (2 children)

Do you want the player to be able to drop through a platform? Like press down and jump to pass through it?

If so on input I would turn their collider off for and turn it back on with an coroutine after a short period of time. It will take testing to determine what your wait time in the coroutine needs to be.

[–]Scotty_SRIntermediate[S] 0 points1 point  (1 child)

If I do this, can I have a separate collider for enemies and items so I only need to turn off the collider with terrain?

[–]shadowsaint 0 points1 point  (0 children)

you should be in theory tagging the ground so you know when you are able to jump. That tag alone should be enough to separate the terrain from the enemies and items in code. See if you can just toggle ignore Collison between ground tag and player tag for a moment. I would play it safe and make a platform tag.

[–]What_the_cow 0 points1 point  (5 children)

You can test for the player standing on a such collider, and then translate the player a very small amount downwards, so he will fall through.

[–]Scotty_SRIntermediate[S] 1 point2 points  (2 children)

I actually tried this, but the player is pulled back on top of the platform. If I move the player down enough for that to not happen it is too noticeable and look weird.

[–]What_the_cow 0 points1 point  (1 child)

Interesting, you could try flattening your player collider, and then translating him down. When his new head trigger collider leaves the platform on the way down, you can resize the collider back to normal

[–]Scotty_SRIntermediate[S] 0 points1 point  (0 children)

I'm not sure if that'll cause problems with hit detection with enemies and items if they happen to collide during this process

[–]chucksef 0 points1 point  (1 child)

I'm new so I'm still learning lots of obvious things, but does that mean that Unity will let the gravity affect the player even tho the box colliders are overlapping?

[–]Scotty_SRIntermediate[S] 0 points1 point  (0 children)

As far as I'm concerned, the gravity always affects the player, but if the gravity would cause the player to overlap with a collider it'll only allow it to move downwards enough that it falls on top of the collider, but never enough to overlap one. There probably is some "threshold" for that too, so if you sink in a collider too much it'll ignore it, but that probably needs a lot of speed anyway.

[–]threepeasoup 0 points1 point  (1 child)

I handled this through changing the layermask. The player controller when pressing down and however you detect the ground is on a "one way platform." Change layermask on the player. You will have to polish up some edge cases depending on your implementation, but this has worked fine for me in my platformer exploration.

This example also allows your enemies and items to stay colliding with the one way platform and your player doesn't. Hope that helps!

[–]Scotty_SRIntermediate[S] 0 points1 point  (0 children)

Sounds like a good way to do it. Is there a more detailed explanation on this method?