B
Binary Orange Studios
Guest
Hi guys,
I am attempting to modify some of Shaun Spalding's code for tile collisions to allow for one way platforms.
So far, it seems to be working, but I'm having some trouble trying to make sure that the collision check is only happening if the player is truly above or at the y position of the tile. This is to ensure that if the player should ever find themselves halfway through the tile horizontally, when they are falling they aren't being "snapped" back to the top.
So far, this is what my code looks like:
It is based off of this code...
I am able to make the player go up through the one-way tile, and when they are traveling down, they are able to collide with the top of it just fine. However, when I am entering through the side of the tile and falling, I will "snap" semi randomly within the tile, until I fall the rest of the way out.
I know that the way to solve this would be to get the bbox_top of the tilemap, and compare it something like this...
...but I'm not sure how to do that, and can't seem to find anything in the manual about that. Am I correct in assuming that only objects have bbox variables? Is there a way to get the bbox of a tilemap at all? Every attempt I have made to access any bbox variables in the tilemap have failed.
Any help and advice is greatly appreciated!
I am attempting to modify some of Shaun Spalding's code for tile collisions to allow for one way platforms.
So far, it seems to be working, but I'm having some trouble trying to make sure that the collision check is only happening if the player is truly above or at the y position of the tile. This is to ensure that if the player should ever find themselves halfway through the tile horizontally, when they are falling they aren't being "snapped" back to the top.
So far, this is what my code looks like:
Code:
#region One Way Collisions
if (tilemap_get_at_pixel(oneway_tilemap, bbox_left, bbox_bottom+vsp) != 0 || tilemap_get_at_pixel(oneway_tilemap, bbox_right, bbox_bottom+vsp) != 0) {
// Make the player collide with the tile only while falling and truly above or at y position of tile
if falling and y >= tilemap_get_y(oneway_tilemap) {
y = y - (y mod 64) + 63 - (bbox_bottom - y);
vsp = 0;
}
}
#endregion
Code:
// Vertical collision
if (vsp > 0) bbox_side = bbox_bottom; else bbox_side = bbox_top;
if (tilemap_get_at_pixel(collision_tilemap, bbox_left, bbox_side+vsp) != 0 || tilemap_get_at_pixel(collision_tilemap, bbox_right, bbox_side+vsp) != 0) {
if (vsp > 0) y = y - (y mod 64) + 63 - (bbox_bottom - y);
else y = y - (y mod 64) - (bbox_top - y);
vsp = 0;
}
I know that the way to solve this would be to get the bbox_top of the tilemap, and compare it something like this...
Code:
if falling && bbox_bottom >= tilemap_bbox_top { do collision }
Any help and advice is greatly appreciated!