• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker [SOLVED] One-Way Platforms Fail When Player Object in Contact with Two Platforms

A

Adam Martinez

Guest
Hello! I'm making one-way platforms. My character can land on top of them from above, and even jump onto them from below, but the character will fall straight down through platforms seemingly when in contact with more than one platform (this happens when my platforms are close together).

I've made progress following this thread...
https://forum.yoyogames.com/index.php?threads/how-would-i-go-about-making-a-one-way-platform.28279/

But I've searched the forum for this particular problem and found nothing.

Here's the code I'm using (inside the player object right now):

var oneway = instance_place(x, y+yspd, obj_platform);
if place_meeting (x, y+yspd, oneway)
&& yspd > 0 {
if bbox_bottom < oneway.y {
while (!place_meeting(x, y+sign(yspd), oneway)) {
y += sign(yspd)
}
yspd = 0
}
}
y += yspd

Any ideas what could be happening? (Thank you!)
 

Kahrabaa

Member
Hello!
If your character touches 2 objects. Then instance_place will only return 1 of them every step.

But based on what youve written, you should not fall through the ground unless they are in different heights.
For example: --_ One high one low platform close enough so you can touch both. You stand on the low one and touch the high one. Then "oneway" would return the high platform ID making your bbox_bottom larger than oneway.y and you fall through the low one.

So a possible solution is to use instance_place_list to check collision with all objects in a place, but may be less efficent.
It would then go like this.
Code:
if(yspd >0){
    if(place_meeting(x,y+yspd,obj_platform)){ //This is for efficency, so we dont use instance_place_list unless there is a platform there
        //Get a list of every platform touching the character
        oneway_list = instance_place_list( x, y+yspd, obj_platform);
        if( oneway_list != noone ) {
           var n = 0;
           while(n < ds_list_size(oneway_list)) { //Loop through list of platforms that touching character
 
               if(bbox_bottom < oneway_list[| n].y){
                   while(!place_meeting(x,y+sign(yspd), oneway_list[| n] )) {
                   y += sign(yspd)
                   }
                   yspd = 0
                   break; //Stop looping through the list, since we already found a platform to snap to
               }
 
               n += 1;
           }
           ds_list_destroy(oneway_list); //Delete list, prevent memory leak
        }
    }
}
I havent tried this so this might not work, but yeah.

The loop code was taken from Aura's post here
https://forum.yoyogames.com/index.php?threads/solved-multiple-collision-check.6635/
You can find the script instance_place_list here
http://www.gmlscripts.com/script/instance_place_list

Note:
instance_place_list uses with( platformobject ).
This will decrease performance if you have alot of platforms in a level.

Good luck
 
A

Adam Martinez

Guest
Hello!
If your character touches 2 objects. Then instance_place will only return 1 of them every step.

But based on what youve written, you should not fall through the ground unless they are in different heights.
For example: --_ One high one low platform close enough so you can touch both. You stand on the low one and touch the high one. Then "oneway" would return the high platform ID making your bbox_bottom larger than oneway.y and you fall through the low one.

So a possible solution is to use instance_place_list to check collision with all objects in a place, but may be less efficent.
It would then go like this.
Code:
if(yspd >0){
    if(place_meeting(x,y+yspd,obj_platform)){ //This is for efficency, so we dont use instance_place_list unless there is a platform there
        //Get a list of every platform touching the character
        oneway_list = instance_place_list( x, y+yspd, obj_platform);
        if( oneway_list != noone ) {
           var n = 0;
           while(n < ds_list_size(oneway_list)) { //Loop through list of platforms that touching character
 
               if(bbox_bottom < oneway_list[| n].y){
                   while(!place_meeting(x,y+sign(yspd), oneway_list[| n] )) {
                   y += sign(yspd)
                   }
                   yspd = 0
                   break; //Stop looping through the list, since we already found a platform to snap to
               }
 
               n += 1;
           }
           ds_list_destroy(oneway_list); //Delete list, prevent memory leak
        }
    }
}
I havent tried this so this might not work, but yeah.

The loop code was taken from Aura's post here
https://forum.yoyogames.com/index.php?threads/solved-multiple-collision-check.6635/
You can find the script instance_place_list here
http://www.gmlscripts.com/script/instance_place_list

Note:
instance_place_list uses with( platformobject ).
This will decrease performance if you have alot of platforms in a level.

Good luck
I just plugged this in and it WORKS AWESOME! Thank you!
 
Top