1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GM:S 1.4 One way platform help

Discussion in 'Programming' started by Dropsuitcaptain, Feb 28, 2019.

  1. Dropsuitcaptain

    Dropsuitcaptain Member

    Joined:
    Feb 8, 2019
    Posts:
    23
    I'm trying to make a one way platform but my code kind of prevents it in a weird way and I need help to fix that.

    I was trying to follow tutorials for this since I've never done it but, since the tutorials had different code than I did I ran into some issues.
    Player step event:
    Code:
    //movement/gravity
    image_speed = 0.1
    if keyboard_check(ord("D")){
        hspd = 2.5;
        sprite_index = sPlayerR;
        image_xscale = 1;
    }else if keyboard_check(ord("A")){
        hspd = -2.5;
        sprite_index = sPlayerR;
        image_xscale = -1;
    }else{
        hspd = 0;
        sprite_index = sPlayer;
    }
    
    if !place_meeting(x,y+1,oWall){
        vspd += grav;
        sprite_index = sPlayerF;
    }else{
        if keyboard_check_pressed(vk_space){
            vspd = -12;
            sprite_index = sPlayerJ;
        }
    }
    //collisions
    if place_meeting(x+hspd,y,oWall){
        while !place_meeting(x+hspd,y,oWall){
            x += sign(hspd);
        }
        hspd = 0;
    }
    if place_meeting(x,y+vspd,oWall){
        while !place_meeting(x,y+vspd,oWall){
            y += sign(vspd);
        }
        vspd = 0;
    }
    x += hspd;
    y += vspd;
    collision with oPlatform event:
    Code:
    if vspd >= 0{
        with oPlatform{
            solid = true;
        }
        vspd = 0;
    }else{
        if vspd <= 0{
            with oPlatform{
            solid = false;
            }
        }
    }
    All I have in my platform object is a create event with "visible = 0"

    Sorry for asking for help so much. Pretty new to this.
    Thanks in advance!
    If there's anymore code you need I can provide.

    EDIT: should've mentioned I think all I need is my gravity to not work while on the platform without bugging out.
     
  2. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,126
    First off, as much as you'll hate to hear this:

    Never was a good method and is one of the reasons that particular tutorial (you watched Shaun's, right?) has been criticized extensively.

    Forget what the exact code is. Study what the code does. That's ultimately how you're supposed to learn from any kind of tutorship.

    1. Are you falling down?
    2. Find the platform you WILL collide with. (var inst = instance_place(x+hspd,y+vspd,oPlatform); )
    3. Are you NOT currently colliding with that instance? (if !instance_place(x,y,inst){ )
    4. Then collide with it.
    Optionally you can check if vspd+grav instead of just vspd.
     
  3. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    2,008
    Step three can also be replaced with "am I above the tile" check (y < inst.y) as the not-colliding check has an edge case where you get stuck if you hit the platform from the side while falling down.
     
  4. Dropsuitcaptain

    Dropsuitcaptain Member

    Joined:
    Feb 8, 2019
    Posts:
    23
    Thank you for your help!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice