How passable (one-way) platforms work in game development!

preview_player
Показать описание
#shorts #gamedev

One-way platforms are very common in platformer games, so in this video I go through how I implemented them in my game.

This game is made with LOVE, feel free to check out my full tutorial:
Рекомендации по теме
Комментарии
Автор

another way: check if y speed is upwards or downwards

ghb
Автор

This video is brought to you by "Solving a computational problem by throwing more processing power at it".

AxidoDE
Автор

You can avoid all the constant checks by checking the collision normal when colliding. The normal will tell you which direction your hitting the platform from. Can just ignore if hitting from bottom 🤟

Stevejustt
Автор

Nice video! Unsolicited fun fact to boost the _algorithm_: In the original Super Mario Bros, the game checks if Mario is landing on an enemy (good) or being landed on (bad) just by checking Mario's vertical velocity component. Thus, you can squash a goomba from below if it lands on Mario while he is falling slower than it.

the-rudolph
Автор

Insane amount of checks per minute… just get the normal of the object or set the normal to a directional vector

snesmocha
Автор

What I did on my one-way platforms was make two hitboxes: one for the bottom and one for the top (in the case of your grated platform, it would be the 2 highest pixels). The bottom hitbox lets anything pass through it, and is just there as a sensor: the higher hitbox would have no collision with anything touching the lower one, but would with anything not touching it.

omegaSomeone
Автор

A trigger collider below the actual collider: I'm about to end this man's whole career

thneitor
Автор

You could also have a check on collision to see if the player is below the position of the platform, and ignore it if it is

zebede
Автор

In godot I just check "one way collision" lol

kaboomsihal
Автор

In Unity you can add a platform effector 2d and it makes it a one way platform automatically, just make sure to check "used by effector" on the collider you are wanting to change.

CallMeCasper_
Автор

Unity has a component called Platform Effector2d that you can attach to your colliders. It ignores collisions from specific directions if you enable the one-way option.

mudspash
Автор

Really cool. The movement and animations of that bird is nice as well.

ImmortalTimothyM
Автор

This works fine if it’s just a single player and simple npcs. However this falls apart if you have add multiplayer or any traversal ai behavior. Also the colliders will spend every frame checking the player’s y position. I’d probably tie the collider flag (i.e. the character’s collision layer) to the entity that is jumping based on it’s movement vector. If a player or entity is moving in the positive y direction, it should not collide with platform. On the way down if it moves in the negative y or is at 0 delta it should check if its collider overlaps the platform. If not then switch the collision flag back. The neat thing with this is you can also make the player “hop down” from the platform by toggling the collider flag based on user input.

austindrexler
Автор

The way I had learnt to solve this is to create a variable to check if you're colliding with the platform or not and if you are, check the y-position until you're above the platform to allow you to pass through or to stop you. I also used this to allow the player to fall through the platform if they're holding down on it.

This was technically intended for allowing sloped platforms but I never used any because I preferred blocky level design.

RobinRhombus
Автор

The velocity check or using the normal is probably the most efficient solution here, but another thing you could do is have another bigger collision box around the platform that checks if the bird is above or below it. So it only checks if the bird is near it, instead of all of the time

cluborronn
Автор

This sounds perhaps computationally heavy? But a nice solution. I always just checked The direction of vertical velocity.

iiropeltonen
Автор

It's more resource efficient to shift the logic from the static platforms to the moving entities passing torugh. Implement a collision check and snap entities above the tile if they try to pass trough them from above. It also enables more than just one entity to do the same simultaneously as the platforms keep their collision state the same at all times.

HerraHissi
Автор

I didn't something similar in 3D for a end of studies project. Rather than check constantly, which doesn't work at scale, I only checked on collision, and then changed the behavior right away. Because I was on Unity and due to how their collision system is built, I just kept it "on" at all times and disabled it if the collision met my criteria (the call was the first step in handling the collision, and changing it to a trigger simply changed the behavior later in the call chain). I could then just enable it back when the character exited the box.
One benefit of this approach was that it was not expensive and was still consistent. One drawback is that it was dependent on engine behavior, we couldn't know if another version of unity could break it. But in the context of our project, we could take the risk, as upgrading our unity version wasn't a current or future requirement.

Exilum
Автор

Imagine doing it this way but for multiplayer. Ya u gonna get alot of bugs. But this is perfect for a singleplayer

sparklee
Автор

Located a bug: if you have an enemy that can jump, they will bonk against any platform lower than the player’s height. Jumping enemies cannot reach the player from below if they are standing on a one way platform

the_furf_of_july
join shbcf.ru