Unable to jump when platform moving down

Hi all!

So far I’ve been able to solve problems through either finding online solutions or having a eureka moment, but I really don’t get this one.

I have a platform game. A moving platform moves vertically. When it moves up, my character behaves as if he is on the floor. When it moves down he keeps falling, landing, repeatedly. This means its hard to make him jump when the platform moves down.

I also have a second problem, in that if my character stands under a moving platform and it collides with him, it must push him down because he can no longer jump. I’ve been having to design my levels so that cannot happen but it’s a hassle.

Thanks for any help!

One way to fix it is to create an object as wide as the platform, but very short e.g. 5 pixels high, that is continuously positioned with an event that puts it at Platform.Y()-5 i.e. it sits just above the platform. You can then check for a collision between this object and the player. If there is one it means the player is on the platform so the action adjusts Player.Y() to equal Platform.Y()-Player.Height(). It would probably be best to also have the condition that the jump key isn’t being pressed. You would also hide the new object at the start of the scene.

This method should work fine if there is only one platform, but if you have several then it becomes more complicated.

An alternative is to reverse the process and have an invisible object always just under the player object, which can be collision checked with whatever the player is standing on and do the Player.Y() = Platform.Y()-Player.Height() action if it is colliding with a vertically moving platform.

For the second problem, I assume you’d prefer the platform to bounce back up off the player’s head. You should be able to achieve this by checking for a player/platform collision and also checking if the Player.Y() value is bigger than the Platform.Y() value. If it is, the player is below the platform, so the action should then reverse the direction of the platform movement.

Thanks, I put an object in to be just below the character, and it works, except now my character doesn’t animate when moving left or right? I have my game set so left key is pressed, play relevant animation. How do I fix that?

I fixed the getting stuck in the ground problem, I didn’t quite do what you said but i did set a collision up where it would move up, I didn’t need to enter anything special, it now moves up when in collision. I didn’t try that because platforms seem to ignore collision checks when standing on them, i guess its only collision when something goes inside a platform. Still, you’ve helped me fix that!

Update: I think I did it wrong. It’s working now, if not perfect - my character can look a bit glitchy when moving left and right, but its not broken anymore!

Cheers!

With the platformer behaviour there is a momentary collision detected when you land on a platform before the software moves the character up, but this is too quick to notice. You can see it happen if you add the following two events, (changing the names of the objects to match your player and platform).

collisionflash.gif

These make the screen go red when colliding and white when not.

You might be able to stop the glitching by switching off gravity (setting to 0) while the invisible object is in collision with the platform and then switching it on again, when it’s not.

That didn’t work either, and gravity 0 isn’t off, had to do minus. Thanks for all your help though :slight_smile:

I resolved that problem in my game long time ago. I’ll upload some pics this weekend or later.
But it goes somehow like this:
When player Y position is platform.Y(centre) -10
And
When player Y position is platform.Y(centre) (or something like that, so player is top of the platform between -10 and centre of that platform)
And
When player X position is platform.X(centre) -10
And
When player X position is platform.X(centre) +10 (width of that platform)

And then when you press jump button player jumps.

BUT as I said, I’ll upload some pics of the code so it makes this all my writing mess more clear :smiley:

MovingPlatform size: 48 x 16
Player size: 32 x 24

movingPl.png
That’s how it works in my game. If you don’t have many moving platforms, those first two conditions ("Player distance… and “pick nearest…”) are useless.

Ps. Also, use trigger once condition if it’s necessary :smiley:

1 Like