Move And Collide with Slopes - Gamemaker Tutorial

Поділитися
Вставка
  • Опубліковано 3 лют 2023
  • Ensure you Like and Subscribe for more exciting Gamemaker content, or check out slyddar.com/ for more info.
    Gamemaker has just released a new move_and_collide function, which allows you to program simple collisions in a very efficient way. You can have a platformer with slopes with a very small amount of code.
    ** What will I learn? **
    In this overview I show how to implement collisions using this new function, and solve a few issues you might encounter when implementing it yourself.
    Chapters
    Sprites - 0:56
    Objects - 2:02
    Create Event - 2:53
    Room Design 3:23
    Step Event - 9:03
    The First Platformer course mentioned in the video will be available shortly, but sign up to my mailing list below to be notified when it's released, and also to receive a special coupon code at launch.
    NOTE: Patreon supporters can download the source code for this tutorial, and also watch any bonus content, over on the Patreon site - / slyddar
    Also I am offering my Tile Based Moving Platform Engine for free, if you have donated at least $20 through Patreon. Contact me if you qualify for this offer.
    Additionally, my Tile Based Moving Platform Engine is available at 25% off via this special link for viewers of my videos - slyddar.itch.io/gm-collisions
    Keepers of Pyrite is currently a work in progress. To get the latest information, follow at / keepersofpyrite or check out the KoP channel in the Discord.
    If you want to learn more GML, check out my Udemy course using the coupon code from my site, which will give almost 90% off.
    How to make Tile Based Platform Games with Gamemaker Sudio 2 - Discounted Coupon Code - slyddar.com/2022/03/01/tile-b...
    The trial version of Gamemaker Studio 2 can be used, and is available here - www.yoyogames.com/get
    Join our community Discord - / discord
    Follow me on Twitter for more Gamemaker content
    Twitter - / slyddar
    Facebook - / slyddar
    If you want to be notified of my new content, or things related to Gamemaker, sign up to my newsletter - eepurl.com/dHBHyn
    Gamemaker is made by Yoyo Games.

КОМЕНТАРІ • 66

  • @goamalo
    @goamalo Рік тому

    Thank you for the great tutorial. I also learned so much from your tile based platformer tutorial and though I didn't use it in the end because the lack of slopes, it taught me a lot of things that made me better at using game maker. Now this tutorial gives a really great base to platformers.

  • @hopcolline2599
    @hopcolline2599 Рік тому +2

    Great job resuming the new function ! First time on your channel, not the last :)

  • @grifleep4916
    @grifleep4916 Рік тому +2

    You're a really great teacher! Some things I like are also showing the visual code and walking through the failuresas well as going over basic stuff again like only using the 1st 3 arguments! It seemed really helpful and can probably help with a rotating platform that was giving me trouble! Thank you!!

  • @jakedouds1186
    @jakedouds1186 Рік тому

    Beautiful mate! Great tutorial!

  • @heroicoder7444
    @heroicoder7444 Рік тому

    thank you dude I kind of needed this. Keep it up

  • @DelphineEraklea
    @DelphineEraklea Рік тому +2

    Oh my god it works, I felt like killing someone after trying to figure out stairs, failing to do so, and then I read that this feature was introduced, and couldn't understand how it works, and then I found this video. Thank you, you stopped me from some extreme actions )))

  • @AdaZoul
    @AdaZoul Рік тому +1

    Great tutorial! \o/

  • @stardreamix786
    @stardreamix786 Рік тому

    Thank you very much

  • @illdie314
    @illdie314 3 місяці тому

    you can set the slope sprite to have a "rectangle with rotation" mask which i believe is much faster than precise collision

    • @Slyddar
      @Slyddar  3 місяці тому

      If you do that you will slide down the slopes when not moving.

  • @barcherellithereal
    @barcherellithereal Рік тому

    Just wondering, but is there a way to add the drag variable from your previous tutorials onto the hsp?

  • @herimito
    @herimito 8 місяців тому +1

    the tutorial really starts at 9:30

  • @memine5595
    @memine5595 Рік тому +1

    Nice

  • @Kiako
    @Kiako Рік тому

    Hey there! I followed along with the tutorial and generally everything works fine, but I noticed a small issue when rapidly shifting directions that causes the player to get stuck on the slope. Is there any fix to this?

    • @Slyddar
      @Slyddar  11 місяців тому

      This can happen if the movement speed is too slow, it's a caveat of the move and collide function itself.

  • @icethechampion
    @icethechampion 7 місяців тому

    I'm a beginner, how would i go about tiling this?

  • @seyuup
    @seyuup Рік тому +1

    Question: does the new method work well with entity acceleration/deceleration?

    • @Slyddar
      @Slyddar  Рік тому +2

      I haven't added it here as I wanted to keep it simple, but it would be super easy, barely an inconvenience.

    • @lang_games
      @lang_games Рік тому

      if(_right_key)
      {
      if(hspd_ < max_speed_)
      {
      hspd_ += accel_;
      } else hspd_ = max_speed_;
      }
      if(_left_key)
      {
      if(hspd_ > -max_speed_)
      {
      hspd_ -= accel_;
      } else hspd_ = -max_speed_;
      }

  • @TheBuckSleezy
    @TheBuckSleezy Рік тому +2

    How applicable is this code for top down, 8-directional movement?

    • @Slyddar
      @Slyddar  Рік тому

      Should work perfectly fine for it.

  • @kadenfrfx
    @kadenfrfx 10 місяців тому

    how would you handle slopes differently to normal tiles? want to make a system like jump king where slopes remove the ability to control the player and slide them in a certain direction

    • @Slyddar
      @Slyddar  10 місяців тому +1

      You could use instance_place to return the id of the solid you are on, and then use that to check if the image_angle of that solid is 0 it's flat, else it's a slope.

  • @adrianmarzec5953
    @adrianmarzec5953 Рік тому

    How to make one way platform with this?

  • @clayton_games
    @clayton_games Рік тому +2

    my player is just falling straight through the floor. any help?

    • @Slyddar
      @Slyddar  Рік тому +1

      I show a screenshot of the code and it's only a screen high. Try pausing it and comparing mine to yours as you have something wrong somewhere.

  • @cobaltdev
    @cobaltdev Рік тому

    because I've made the player go faster, how would i increase the clamp to a higher amount?

    • @Slyddar
      @Slyddar  Рік тому

      If you set move_spd to a higher value it should move quicker.

  • @druinn
    @druinn 5 місяців тому

    That video is AMAZING!!!! Quick question, if I change the variable move_spd to 5 or 6 the problem with the slopes start again (the player start jumping them) could you pls mention a solution for that pls!

    • @druinn
      @druinn 5 місяців тому

      Do you have an anwer or a suggestion for me?

    • @Slyddar
      @Slyddar  5 місяців тому +1

      When you add more speed, the 1 pixel we are checking below us to adhere to the slope will not be enough. You will need to increase that value to look more than 1 pixel below. Still leave the y += 1 though, but increase the place_meeting check value from 1 to 2, 3, 4, etc . You'll have to test values starting from 2 to see if it helps.

    • @druinn
      @druinn 5 місяців тому

      @@Slyddar problem totally solved!!! thanks SO much! all your videos are clear are helps a lot!

  • @jordanedwards3114
    @jordanedwards3114 6 місяців тому

    my player keeps randomly falls through the slopes....any ideas as to why?

  • @samthesoupman6385
    @samthesoupman6385 Рік тому

    player's got some jittery movement on the floor, tips on how to fix that?

    • @Slyddar
      @Slyddar  Рік тому

      Did you enable compatibility mode?

  • @gluehole4036
    @gluehole4036 Рік тому +1

    Could you make a tutorial on one-way platforms using this code?

    • @Slyddar
      @Slyddar  Рік тому +3

      Sounds like a cool idea, so... maybe :)

  • @MrOdmincheg
    @MrOdmincheg Рік тому

    Hi! I can't find your new course on udemy.

    • @Slyddar
      @Slyddar  Рік тому +1

      Hi, thanks for the interest. Unfortunately I’m still finalising the course details on the Udemy site, but it should be available in early April though.

  • @fierorecensione5828
    @fierorecensione5828 Рік тому

    Hei ya! Thank you for this videos, i bought your tile based platform course on Udemy, i also checked your new one course but i didn't find it!

    • @Slyddar
      @Slyddar  Рік тому +1

      Hey thanks for the support! The new course is complete, but it's only the Visual section at the moment. I was waiting until I finish the GML section before releasing it, so a few more weeks unfortunately :(

    • @fierorecensione5828
      @fierorecensione5828 Рік тому

      @@Slyddar ok thank you, i will waiting

  • @MichaelSchultzSF
    @MichaelSchultzSF Рік тому +1

    Wait, you're never setting the players x position variable. How does the player object even move without setting it?

    • @Slyddar
      @Slyddar  Рік тому +1

      move_and_collide applies the passed variables to the x and y position.

  • @donsoyer
    @donsoyer Рік тому

    What about collisions with tiles? I don't use objects but tiles. What about that?

    • @Slyddar
      @Slyddar  Рік тому

      Move and collide is aimed at object collisions only. I haven't heard anything about them making it work for tiles too. I have a Udemy course which shows a great way to implement tile collisions, and make a complete game at the same time, if that interests you, but I also understand it's much more complex than this great function.

    • @donsoyer
      @donsoyer Рік тому

      @@Slyddar Oh, I have also course on udemy with it, so thanks

  • @devcui
    @devcui Рік тому

    How to realtime game for multiplayer

  • @unsoga
    @unsoga Рік тому

    please write the code from the video in the comments, nothing works for me

  • @sproins
    @sproins 11 місяців тому

    Having some issues. When you hold a direction against a wall while jumping the sprite jitters and the jump height doubles. Can also get extra height if you graze against the side of a platform. I've tried this tutorial, and a few others and get the same results. I can mostly fix it but it starts getting more complicated than it should be. Should I just not use move_and_collide for slopes? Or am I missing something?
    Edit: i switched to godot, problem solved :)

  • @ireallydontknow4754
    @ireallydontknow4754 Місяць тому +1

    i like skibidi 😎😎😎

  • @jackasscilva
    @jackasscilva 4 місяці тому

    caraca tão difi´l ser programador hoje em dia

  • @jackasscilva
    @jackasscilva 4 місяці тому

    pricipalmente no game maker

  • @itsybutsy
    @itsybutsy Рік тому +4

    Doesn't work. Player character just falls through all blocks.

    • @Slyddar
      @Slyddar  Рік тому +2

      Obviously it does work, as the video shows it working. It's more a question of where you went wrong.

    • @clayton_games
      @clayton_games Рік тому +2

      @@Slyddar I copied your code and I'm having the same problem. So where do we look for fixing this problem?

    • @Slyddar
      @Slyddar  Рік тому +1

      Come to the discord and someone might be able to help you.

    • @clayton_games
      @clayton_games Рік тому +1

      @@Slyddar posted

    • @Slyddar
      @Slyddar  Рік тому +1

      @@clayton_games And answered in the discord. For anyone else, hspeed and vspeed are not the same as hsp and vsp. Ensure you use the same variables and code I do otherwise it may not work.

  • @soubakouh
    @soubakouh Рік тому +1

    idk what I do bad :(
    #region plat_init
    function plat_init(_maxspd,_acc,_desacc,_jmpspd,_grv,_maxvsp,_maxslope,_solid_par,_solid,_slope) {
    //ex: plat_init(8,0.3,0.1,16,0.5,16);
    maxhsp = _maxspd;
    acc = _acc;
    desacc = _desacc;
    maxjump = -_jmpspd;
    grv = _grv;
    maxvsp = _maxvsp;
    hsp = 0;
    vsp = 0;
    hsp_frac = 0;
    dir = 0;
    maxslope = _maxslope;
    solid_par = _solid_par;
    solid_obj = _solid;
    slope_obj = _slope;
    }
    #endregion
    #region plat mechanics
    function plat_mechanics(_key_left,_key_right,_key_jump) {
    var _move,_col,_frc,_mac;
    _move = _key_right-_key_left;
    _col = place_meeting(x,y+maxslope,solid_par);

    //friction
    if !place_free(x,y+1) { _frc = desacc; }
    else { _frc = desacc/8; }

    //calc movement
    if (_move != 0) { hsp += _move*acc; }
    else { hsp = median(hsp+_frc,0,hsp-_frc); }
    vsp += grv;

    //speed limits
    hsp = median(-maxhsp,hsp,maxhsp);
    vsp = min(vsp,maxvsp);

    //jump
    if (_key_jump) && !place_free(x,y+1) { vsp = maxjump; }

    //adherir al suelo en bajadas
    if (_col) && !place_meeting(x,y+maxslope,solid_obj) && (vsp > 0) {
    while !place_meeting(x,y+1,slope_obj) { y++; }
    }

    //move and collide
    _mac = move_and_collide(hsp,vsp,solid_par);
    if ( array_length(_mac) != 0 ) && place_meeting(x,y+vsp,solid_par) { vsp = 0; }
    }
    #endregion
    up the slope, but in final stops, and stops when try to down too.

  • @herimito
    @herimito 8 місяців тому

    if you happen to know how "not" to clamp to the nearest platform when jumping next to it, please add to this code too... it was the poorest code I ever seen!