• 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!

Legacy GM How Would I Go About Making A One Way Platform

NightFrost

Member
One-way platforms are one of the first speed bumps for beginner platformer developers. They need to be their own object type. Generally, you will only consider collisions with one-way platforms for vertical movement checks, they never block horizontal movement. When player is moving upwards, you ignore checking collisions with one-way platform objects. When player is moving downwards, you will check for one-way platform objects too, but only handle them if player's starting position during the step was above the object. This way, while player is falling through a one-way platform, it will not stop their movement.
 
K

koopy eacret

Guest
Yes But How Do I Detect which Angle The Player Is Coming From,I Tried Place Meeting
And It Did Not Seem To Work.
 
K

koopy eacret

Guest
Here Is My Collision Code With Normal Solids(Not One-Ways),Its Pretty Generic.
The Arrow Keys Add A Value To Hspd And Vspd

Code:
if place_meeting(x+hspd,y,obj_solid){
    while !place_meeting(x+sign(hspd),y,obj_solid){
            x+=sign(hspd);
        }  
        hspd=0;
    }
   
x+=hspd

if place_meeting(x,y+vspd,obj_solid){
    while !place_meeting(x,y+sign(vspd),obj_solid){
            y+=sign(vspd);
        }  
        vspd=0;
    }
   
y+=vspd
 

NightFrost

Member
It is the vspd check that needs the additional check for one-way platform objects. You must use instance_place for that check, because you need to be able to read the object's y-position. However you only need to do this when your vspd is above zero - that is, the player is falling down.
 
K

koopy eacret

Guest
Oh Okay, May I Ask For An Explanation On Want Place_instance Does?
 

NightFrost

Member
Ah, right, I forgot to go into detail. Instance_place returns the id of the colliding object, so you need to store that into a variable for later use:
Code:
var OneWay = instance_place(x, y+vspd, obj_oneway);
And you would refer to its y-position later by reading
Code:
OneWay.y
Note that for this to work the one-way platform sprite's y-origin needs to be zero.
 
K

koopy eacret

Guest
So In The Vertical Collision I Just Need Too Put (if !oneway.y) Along With The Collision Code?
 
M

Marcos Mena

Guest
If you haven't figured it out yet I'm sure this will help you greatly.

GameMaker: Studio - One Way Platforms:
 

sp202

Member
The simplest thing to do is to do a collision check below the player for the platform object, disable solid and any other built in collision you might have.
 
K

koopy eacret

Guest
Night Frost Helped,I Just Want To Know Were I Am Supposed To Reference The Oneway variable...
 

sp202

Member
oneway.y is referring to the y value of the platform instance below the player, you should know how to procede from there. Also, why do you capitalize every word?
 
K

koopy eacret

Guest
oneway.y is referring to the y value of the platform instance below the player, you should know how to procede from there. Also, why do you capitalize every word?
Because I Do What I Want...
 

NightFrost

Member
I'm not at my dev machine with the GM install so I can't verify this code runs, but it should go like this (replace your vspd check with this code). Note that I changed to y position check to be against bbox_bottom because your player sprite's origin point might not be at the bottom of the sprite, as you might need it to be elsewhere. And just to reiterate, oneway platform sprite's y-origin needs to be zero (at the very top).
Code:
// First we do the collision checks but place the results into variables for clarity.
var Solid = place_meeting(x, y + vspd, obj_solid);
var OneWay = instace_place(x, y + vspd, obj_oneway);
// Then we check from those variables if either type of collision is occuring at y+vspd position.
// We check the collision with one-way tile only if player is falling downwards and the bbox_bottom BEFORE vspd is applied is above the object.
// Because instace_place returns -4 when no collisions occur, it can also be read as true/false check.
if(Solid || (OneWay && vspd > 0 && bbox_bottom < OneWay.y)){
    // Then we do the usual while-loop. Because this code only runs if we're jumping/falling into a solid, or falling into a one-way from above,
    // there is no need to check direction and y position again and place_meeting can be used instead.
    while(!place_meeting(x, y + sign(vspd), obj_solid) && !place_meeting(x, y + sign(vspd), obj_oneway)){
        y += sign(vspd);
    }
    vspd = 0;
}
y += vspd;
 
I Have Watched It In The Past It Did Not Work...
You should go through the entire playlist related to that video. I did the same series and it DOES work. Shaun Spaulding's videos are top notch and an excellent way to learn the basics (which can be applied to a great many types of games, not just platformers).

Also... what is with the uppercase letter on each word, it makes everything you type that much more annoying and ridiculous looking. It shows that you may not really be so serious about learning, makes me wonder if anyone should bother spending their time helping you. Good luck!
 
C

Christopher Rosa

Guest
You should go through the entire playlist related to that video. I did the same series and it DOES work. Shaun Spaulding's videos are top notch and an excellent way to learn the basics (which can be applied to a great many types of games, not just platformers).

Also... what is with the uppercase letter on each word, it makes everything you type that much more annoying and ridiculous looking. It shows that you may not really be so serious about learning, makes me wonder if anyone should bother spending their time helping you. Good luck!
It does work but there's a problem where if you're jump doesn't reach to the top of the platform and youre vsp < 0 meaning you're falling you will get stuck in the platform
 
I

Ishan Shrestha

Guest
inside the one way platform

if (player.y>y) mask_index = sp_any_sprite_with_no_collision_mask
if (player.y<=y) mask_index = sp_actual_sprite

inside player collsion to the platform

if(y<other.y) {
vspeed=0
move_contact_solid(270,12)
}
 
Last edited by a moderator:
Top