Creating a one-way collision platform

Hi, I’ve been messing with the concept of a sort of 2D arena, and was having some trouble surrounding getting one-way platforms to work. By this I mean platforms which you will not collide with if you jump up from under them, but perfectly solid if you stand on top of them from above. The difficulty is the multiplayer aspect since if someone is standing on a platform, another player must still be able to jump through the platform from below.

I’ve spotted collision groups as a possible method to solving this: I could have a collision group for the platform, players under the platform and players above the platform and set collision accordingly (dropping off a platform can, again, be handled by a collision group change), but I still wanted to ask:

A) Is there something fundamentally wrong with this approach that I am missing? Is there some major inefficiency or issue with collision groups that makes this a problematic solution?

B) Assuming I can use collision groups, I need an event that will trigger the function to change collision groups when a character’s position goes above/below the platform. Propertychangedsignal comes to mind but it does not seem like the best solution to call the function every time the Y position changes and compare. Is there a better method for calling a function when the humanoidrootpart hits a specific Y position?

2 Likes

A approach that I’ve used in the past is raycasting or checking the characters Y-Velocity. Using this information, you can basically make parts below them solid and parts above not.

You can do this every render step and adjust the can collide of each part on the client. This will allow others to still step on the platforms without issue.

Hopefully this helps :slight_smile:

That would certainly help with part B, although I’m still curious about the potential merits of collision groups.

1 Like

I remember doing something like this long time ago with a 2D platformer.
I would check the lower edge of the character’s bounding box and see if it is above the platform’s upper bounding box.

If it is, that’ll be a solid found.
If not, you jump right through it.

If you jump onto another platform and don’t quite make it, you go through the platform and land on the lower one.

1 Like

What would you do for objects that are not the player? Surely there is an easier way than rendering each object individually with a raycast for the platform?

I’m not too sure if it’s the best way of going about platforms, but what I did for a game I made was making a seperate collision group for platforms(every platform uses the same collision group) and making 2 seperate collision groups for the player: one that collides with platforms, and one that doesn’t.

Every frame(using Stepped), I’d check the Y velocity of the player’s root part, and if it was more than zero(you can also do more than or equals to zero), I’d set the collision group of the player’s root part to be the version of the player’s collision group that doesn’t collide with platforms, and otherwise I’d set it to be the version of the player’s collision group that does.

It worked pretty good in practice, but it may not be a very good tactic, though I hoped it could help, since there wasn’t a solution for your problem yet.