#One Way Platform Collisions

15 messages · Page 1 of 1 (latest)

scarlet saddle
#

Hey,

I am having an issue with one way platforms and I can't figure out how to approach the solution.
For the most part, the collisions work perfect. The issue arises when i have stacked one way platform tiles. The problem is clearly shown in the GIF i attached.
I understand why it happens, I just have no idea about how to alter my code to deal with this situation.

For my collisions I am using a script (a modified version of the collision script provided in the Platformer Template).
To handle one way platforms, I'm checking if we move from a non-platform tile into a platform tile (this prevents the character getting stuck inside the tile).
Obviously, this doesn't work then the platform tiles are stacked, as we are moving from platform tile to another platform tile.

I will add code to the comments since I hit the limit

#

Collision script

function check_collision(_move_x, _move_y) {
    var _right_bottom = tilemap_get_at_pixel(obj_game_manager.collision_tilemap, bbox_right + _move_x, bbox_bottom + _move_y);
    var _left_bottom = tilemap_get_at_pixel(obj_game_manager.collision_tilemap, bbox_left + _move_x, bbox_bottom + _move_y);
    var _current_bottom_left = tilemap_get_at_pixel(obj_game_manager.collision_tilemap, bbox_left, bbox_bottom);
    var _current_bottom_right = tilemap_get_at_pixel(obj_game_manager.collision_tilemap, bbox_right, bbox_bottom);
    if (_move_y > 0 && (_current_bottom_left != PLATFORM && _current_bottom_right != PLATFORM) && (_right_bottom == PLATFORM || _left_bottom == PLATFORM)) {
        return true;
    }
    return _right_bottom == SOLID || _left_bottom == SOLID;
}

and it is called in my step event

var _y_move_count = abs(velocity_y);
var _y_move_once = sign(velocity_y);

repeat (_y_move_count) {
    var _collision_found = check_collision(0, _y_move_once);
    if (!_collision_found) {
        y += _y_move_once;
    } else {
        velocity_y = 0;
        break;
    }
}

I've excluded the horizontal logic to keep it concise

trim garnet
#

Does it have to be from a non platform tile?

scarlet saddle
#

I don't understand your question, sorry. I included another GIF to show a few examples of the platform collisions failing.

trim garnet
#

You said to handle one way platforms you check if you move from a non platform tile into a platform tile. Does it have to be from a non-platform tile? Could it just check if you enter a platform tile from any tile?

scarlet saddle
#

Nope, it causes the character to get stuck inside a tile. That's why I was checking if we are moving **into **a platform rather than in a platform

trim garnet
#

I've never programmed platform collisions like this before, so I wouldn't know the best way to do it. But the thought that comes to my mind is to just check if you're entering a tile that you weren't already inside of previously. if that's possible.

dim lava
#

You could try checking for a collision only from below your player and only for the top bounding box of your platform.

#

it would look something like this
var _object_collide = instance_position(x,y+vspd,obj_platform);
if(_obj_collide != noone) && (bbox_bottom - _obj_collide.bbox_top < vspd) {
y = _obj_collide.bbox_top - 1;
vspd = 0;
}

#

Of course you would want to make sure you only check this on a down arc. This would naturally allow you to move through platforms in any direction except down, and only if you are above it. You wouldn’t even need to know where you started the jump from.

#

This would need tweaks and there’s other ways to code it, but I hope this helps.

scarlet saddle
#

My one issue with that is that I am using a collision layer and not objects. I was hoping to adjust what I have rather than a rework.
I will play around with your suggestion and see what I can discover

dim lava
#

Sorry, I’ve been writing this from my phone and it’s hard to be precise lol

scarlet saddle
#

I manged to find a solution with some quite questionable code. I can now refactor it to be less chaotic 🙂

The code is too large to write here so I will add a screenshot for completion.
Thanks to all for your suggestions!