magnetar
magnetar

Reputation: 3

Gamemaker, one way platform

movingPlatform This is the jump through platform I used in my game. If I jump on it, character can't stand on it again so the player falls off the platform.

My code:

...
move_dir = right_key - left_key
x_speed = move_dir * move_speed;
// Y MOVEMENT
y_speed += grav;
if jump_key && (place_meeting( x, y + 1, collision_objects) || place_meeting(x, y + 1, oplatformmoving))
{ 
    y_speed = jump_speed;
}

// COLLISIONS
// Moving Platform Collision
var _movingplatform = instance_place(x, y + max(1, y_speed), oplatformmoving);
if (_movingplatform && bbox_bottom <= _movingplatform.bbox_top) {
    if (y_speed > 0) {
        while (!place_meeting(x, _movingplatform.bbox_top, oplatformmoving)) {
            y += sign(y_speed);
        }
        y_speed = 0;
    }
    x += _movingplatform.moveX;
    y += _movingplatform.moveY;
}
...

I want to jump on the platform again and again.

Upvotes: 0

Views: 62

Answers (1)

YellowAfterlife
YellowAfterlife

Reputation: 3217

There are two easy ways to do one-way platforms:

  1. Consider platforms as solid only on the way down
  2. If the player is the only entity that can collide with them, you may straight up disable collision masks for any platform with y <= player.bbox_bottom

Now, as for your code, try running the game in debug mode or add a

show_debug_message(bbox_bottom);
if (_movingplatform) show_debug_message(_movingplatform.bbox_top);

Bounding box coordinates are inclusive, so you might be off by a pixel.

Upvotes: 1

Related Questions