GameMaker Studio 2 - Random Level Generation P2 - Player and Collisions

Поділитися
Вставка
  • Опубліковано 21 жов 2024

КОМЕНТАРІ • 83

  • @Slyddar
    @Slyddar 6 років тому +5

    Great tutorial series as always Ben. Thanks for sharing.
    As for the stuttering, it happens because you are moving in fractions, yet trying to do this against tiles requiring integers. Shaun highlighted the problem recently in his video too. The solution is to add this code before your movement code in order to round the movement per step. Also define the variables x_speed_fraction and y_speed_fraction in create of course.
    //reapply the fractions
    x_speed_ += x_speed_fraction;
    y_speed_ += y_speed_fraction;
    //store and remove the fractions
    x_speed_fraction = x_speed_ - (floor(abs(x_speed_)) * sign(x_speed_));
    x_speed_ -= x_speed_fraction;
    y_speed_fraction = y_speed_ - (floor(abs(y_speed_)) * sign(y_speed_));
    y_speed_ -= y_speed_fraction;

    • @uheartbeast
      @uheartbeast  6 років тому

      Thanks! I'll update the github page.

    • @ArmandtvanRooyen
      @ArmandtvanRooyen 6 років тому

      Could you perhaps link that video of Shaun please?

    • @Slyddar
      @Slyddar 6 років тому +1

      I'm not sure if it's ok with Ben to share another tutorial here, but I'm sure he can remove it if it's not.
      ua-cam.com/video/Yre-XAE8DBA/v-deo.html

    • @ArmandtvanRooyen
      @ArmandtvanRooyen 6 років тому

      Thank you kindly :D

    • @pudgedev1308
      @pudgedev1308 6 років тому

      I don't know if you're still active, but diagonal movement makes the player stutter with this code. Do you think it's because of my code or this code?

  • @Kebaskia
    @Kebaskia 2 роки тому +8

    From 10:05 the script needs to be wrapped in a function.
    function grid_place_meeting(_object, _grid) {
    var _top_right = _grid[# (_object.bbox_right-1) div CELL_WIDTH, _object.bbox_top div CELL_HEIGHT] == VOID;
    var _top_left = _grid[# _object.bbox_left div CELL_WIDTH, _object.bbox_top div CELL_HEIGHT] == VOID;
    var _bottom_right = _grid[# (_object.bbox_right-1) div CELL_WIDTH, (_object.bbox_bottom-1) div CELL_HEIGHT] == VOID;
    var _bottom_left = _grid[# _object.bbox_left div CELL_WIDTH, (_object.bbox_bottom-1) div CELL_HEIGHT] == VOID;
    return _top_right || _top_left || _bottom_right || _bottom_left;
    }
    Had me stumped for a while, but that's the life of a programmer I guess.

    • @grandnemesis4480
      @grandnemesis4480 2 роки тому

      @@chewymang8597 It's because this tutorial was made before GMS2.3, which changed how scripts work.

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

      thank you so much! my bren also melt during this part

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

      Awesome, thanks ;)

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

    If you are bothered by the gap in some walls and you want to close the border, you can do this:
    Create a 1 x 9 sprite with the border color, set the origin to 16x 9 and at the object level in the draw event, copy this:
    For (var _y =1; _y < height_-1; _y++) {
    For (var _x =1; _x < width_-1; _x++){
    If (grid_[# _x, _y] != floor) and (grid_[# _x +1, _y] == floor) and (grid_[# _x +1, _y -1] != floor) and (grid_[# _x , _y -1] != floor){
    Draw_sprite_ext((sprite name), 0, _x*cell_width+16, _y*cell_height,-1,1,0,c_white,1);
    For (var _y =1; _y < height_-1; _y++) {
    For (var _x =1; _x < width_-1; _x++){
    If (grid_[# _x, _y] != floor) and (grid_[# _x -1, _y] == floor) and (grid_[# _x -1, _y -1] != floor) and (grid_[# _x , _y -1] != floor){
    Draw_sprite_ext((sprite name), 0, _x*cell_width+16, _y*cell_height,1,1,0,c_white,1);
    Pd: there could be a better way to do that but i am starting at programming

  • @BenTu578
    @BenTu578 7 місяців тому +1

    Excellent tutorial. My solloution to the issue with the border was to make a sprite 32x32 and make it a solid color and enable 9 slice(you can also just make it invisible after you place it by putting it on another instance layer)
    Then create a object from that sprite and I named mine "o_walls"
    I placed one on the top left corner and then proceeded to outline the entire edge of the map that I did not want to go past.
    In the player step event, I modified the code so that it could also detect the walls. Here is the code as I made it. It could also be added as another variable in the script.
    if x_spd > 0 {
    image_xscale = 1;
    if grid_place_meeting(self, o_level.grid_) || place_meeting(x+ x_spd,y, o_walls) {
    x = bbox_right&~ (CELL_WIDTH - 1)
    x-= bbox_right -x;
    x_spd = 0;
    }
    } else if x_spd < 0 {
    image_xscale = -1;
    if grid_place_meeting(self, o_level.grid_) || place_meeting(x- x_spd,y, o_walls) {
    x = bbox_left&~ (CELL_WIDTH - 1)
    x+= CELL_WIDTH+ x- bbox_left;
    x_spd = 0;
    }
    }
    y += y_spd;
    if y_spd > 0 {
    if grid_place_meeting(self, o_level.grid_) || place_meeting(x,y+ y_spd, o_walls) {
    y = bbox_bottom&~ (CELL_HEIGHT - 1)
    y-= bbox_bottom -y;
    y_spd = 0;
    }
    } else if y_spd < 0 {
    if grid_place_meeting(self, o_level.grid_) || place_meeting(x,y- y_spd, o_walls) {
    y = bbox_top&~ (CELL_HEIGHT - 1)
    y+= CELL_HEIGHT+ y- bbox_top;
    y_spd = 0;
    }
    }

  • @Sora-fy8no
    @Sora-fy8no 6 років тому +10

    Do you intend to add a room of fixed room items, such as the one in the game "enter the gungeon"?

    • @fiercefox9276
      @fiercefox9276 2 роки тому

      you forgot the "the" in the game title

    • @Sebkir.
      @Sebkir. Рік тому

      @@fiercefox9276 helpfull coment

  • @monet5889
    @monet5889 6 років тому +2

    The issue with the player bouncing off of the right and downwards walls is related to acceleration being a decimal, it works fine when the acceleration value is a whole number

  • @nickgennady
    @nickgennady 5 років тому +3

    Wow great tutorial. Only recommendation is to go over the algorithm visually before you program so some of us may try to do it without tutorial first. I like how you got us started but its up to us to figure the rest out.
    I changed some stuff to add holes in the ground and random start position instead of center. Just need to add stairs and bad guys. I'm thinking of having ability to generate levels from a text file. Lets say you have a dungeon with 10 floors. You want the 5th to have a diffrent exit condition like killing bad guys instead of finding stairs or the 10th floor being a randomly generated but open area with a boss fight. Not really sure what I wan't to do but I think water would be cool to :).
    Again thanks for the awsome tutorial.

    • @gavinandrews6887
      @gavinandrews6887 2 місяці тому

      sounds super cool! I know I'm five years late but did you ever finish it / have a playable file?

  • @Merlin042
    @Merlin042 6 років тому +3

    Nicely done! Thank you!

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

    Hi I was wondering how to add a door to this but randomly generated can you tell me if it is similar to making o_level?

  • @Z3R03N3S
    @Z3R03N3S 5 років тому +2

    So I watched this series about generating random dungeons but unfortunately to spawn enemies into the grid I needed to watch the older series which were done with gms1 and so i tried but it gives me this error message, that I need to define grid_path...I actually defined it but its not enough for gms2...can anyone help me, pls?

  • @Stevee315
    @Stevee315 3 роки тому +1

    Hey @HeartBeast so I've been following your tutorial but for some reason the character is hitting invisible walls that are in the room itself. I'm not entirely sure what went wrong. If you had a piece of advice that would be amazing.

  • @Ekozaak
    @Ekozaak 5 років тому +1

    Great tutorial but how can i do a collision line ? I tried to make an object with a variant image_xscale, but as the sprite become bigger than a cell width it does not work well

    • @Ekozaak
      @Ekozaak 5 років тому +1

      I found something, I did the best i could, it works but it's not clean
      //Scale and angle
      image_angle = point_direction(target.x,target.y,obj_player.x,obj_player.y)
      image_xscale = clamp(point_distance(target.x,target.y,obj_player.x,obj_player.y),-16,16)

      //If len is bigger than the distance
      if len+16 > point_distance(target.x,target.y,obj_player.x,obj_player.y) {
      // If there was a collsion
      if coll {
      //Collision set to true
      target.wallfront = true
      } else {
      //Collision set to false
      target.wallfront = false
      }
      //Reset the collsion and the len
      coll = false
      len = 0;
      }

      //Add 16 to len and check if there is a collsion
      x = target.x+lengthdir_x(len,image_angle)
      y = target.y+lengthdir_y(len,image_angle)
      if grid_place_meeting(self,obj_level.grid_) {
      coll = true
      }

      len +=16

  • @Z3R03N3S
    @Z3R03N3S 6 років тому +1

    nice tutorial bro...but can you also code that if the player eneter a certain place of the level, then the level will automatically random generate?

  • @michaelmahon3725
    @michaelmahon3725 6 років тому

    delayed post, but just found this great tutorial. For some reason, the clean up event with ds_grid_destroy is not working - there is still memory bleed every time I restart. I can't for the life of me figure out why - any thoughts?

  • @jizosgoescrazy
    @jizosgoescrazy 4 роки тому +1

    The grid_place_meeting don't works anymore any help ?

    • @Emily-lc2uj
      @Emily-lc2uj 3 роки тому +1

      damn, I'm having the same issue. I've checked over my code to make sure it matches over and over but I still get the error:
      ############################################################################################
      ERROR in
      action number 1
      of Create Event
      for object :
      Variable .bbox_top(23, -2147483648) cannot be resolved.
      at gml_GlobalScript_grid_place_meeting (line 10) - var _top_right = _grid[# (_object.bbox_right-1) div CELL_WIDTH, _object.bbox_top div CELL_HEIGHT] == VOID;
      ############################################################################################
      gml_GlobalScript_grid_place_meeting (line 10)

    • @stryderjoeofficial2790
      @stryderjoeofficial2790 3 роки тому +1

      @@Emily-lc2uj same

    • @d4fm
      @d4fm 3 роки тому +6

      Here is the correction
      ///@function function grid_place_meeting(_object, _grid)
      ///@arg object
      ///@arg grid
      function grid_place_meeting(_object, _grid){
      var _top_right = _grid[# (_object.bbox_right-1) div CELL_WIDTH, _object.bbox_top div CELL_HEIGHT] == VOID;
      var _top_left = _grid[# _object.bbox_left div CELL_WIDTH, _object.bbox_top div CELL_HEIGHT] == VOID;
      var _bottom_right = _grid[# (_object.bbox_right-1) div CELL_WIDTH, (_object.bbox_bottom-1) div CELL_HEIGHT] == VOID;
      var _bottom_left = _grid[# _object.bbox_left div CELL_WIDTH, (_object.bbox_bottom-1) div CELL_HEIGHT] == VOID;
      return _top_right || _top_left || _bottom_right || _bottom_left;
      }

    • @Maddzy1
      @Maddzy1 2 роки тому

      @@d4fm HERO!

  • @ZoidbergForPresident
    @ZoidbergForPresident 6 років тому

    Just to be sure: ds_grid_create() creates a 2D matrix? Is it just that or is there some specific gamemaker thing related to it?
    11:32 why the -1 for right but not for top?
    Also, how do you make it so the player doesn't spawn in an empty/VOID tile?

    • @rogercollins239
      @rogercollins239 6 років тому

      There's a typo in his o_level:Create function. Change the following lines:
      var _player_start_x = _controller_x * CELL_WIDTH + CELL_WIDTH / 2;
      var _player_start_y = _controller_y * CELL_HEIGHT + CELL_HEIGHT / 2;

  • @thomaswareing2976
    @thomaswareing2976 5 років тому +1

    Hi thanks for the tutorial. What do I need to do to make it so the squares are 64 by 64 rather 32 by 32?
    Thanks.

  • @lakesideview2203
    @lakesideview2203 6 років тому +7

    This is so cooool!!!! Do you plan on adding a system to have things like items and monsters randomly appear in the dungeon too?

    • @uheartbeast
      @uheartbeast  6 років тому +3

      Check out P6 of the older series. It is GMS 1.4 but the general idea will be the same :)
      ua-cam.com/play/PL9FzW-m48fn2gQVYFxDzq4cz2A4uGWusx.html

    • @narulan9325
      @narulan9325 6 років тому

      HeartBeast Hey, HeartBeast my player is running too fast.I don't know what I did wrong, I just wrote the code just like you

    • @drtech70
      @drtech70 4 роки тому +1

      @@uheartbeast i dont know how to implement the code for your old spawning enemies with tilemap collision into game maker studio 2 2.3 ver

  • @Jonathan-el2gk
    @Jonathan-el2gk 6 років тому +1

    Hey guys,
    I was wondering if I could get some help. I basically tried using this tutorial and did. it worked, but then I wanted the room size to be random and when I created on ubject that set the room size to a random integer using room_set_width(r_one,irandom_range(1024,2048)) and room_set_height(r_one,irandom_range(1024,2048)), but then it would create the walls and the shadows but not draw the wall tiles. I was wondering if I could get some help on this.
    Here is the code for the object that creates the o_level object:
    room_set_width(r_one,irandom_range(1024,2048))
    room_set_height(r_one,irandom_range(1024,2048))
    instance_create_layer(x,y,"Level",o_level)

  • @Imperium6Divine
    @Imperium6Divine 6 років тому +1

    I cannot think of a way to adjust the collision so player can walk behind the bottom wall tiles to really give it that perspective. It seems that even if you do fix the collision with those tiles you still have to find a way to adjust the depth.

    • @DionGrimm
      @DionGrimm 6 років тому

      In theory you could have another tile layer on top of your instances which functions as a "roof". It would be the same as the wall layer except it won't have the top wall tiles. I haven't tried to implant this in the level generator though.

    • @Imperium6Divine
      @Imperium6Divine 6 років тому

      Yeah, great idea. I had tried to accomplish this by drawing the tile on a different tile layer in the room and then be sure to have the player on a layer above it. It works for now lol

  • @drtech70
    @drtech70 4 роки тому

    how could i spawn enemies randomly but not in walls...where the collision detection checks to see if there are tiles and than spawns the enemies in a free space.

  • @gaspargazzera45
    @gaspargazzera45 6 років тому

    Heart a question when will you see a 3 part waxing new things?

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

    How would I randomise enemy spawns?

  • @darrylwolfe7359
    @darrylwolfe7359 3 роки тому

    What language is used in GameMaker?

  • @AUSxTECHxGUY
    @AUSxTECHxGUY 6 років тому

    Will the code for wall shadows work in GMS 1.4?

  • @Beefyjesus0
    @Beefyjesus0 6 років тому +1

    Ive gone over the code multiples times and everything seems perfect. But my character moves perfectly until i collide with a wall and than he teleports to the top left, any ideas?

    • @Beefyjesus0
      @Beefyjesus0 6 років тому

      Actually figured this out. Cant use and in replace of & when dealing with bitwise operators.

    • @Tacoburito
      @Tacoburito 5 років тому

      @@Beefyjesus0 didn't really understand what you wrote

    • @Beefyjesus0
      @Beefyjesus0 5 років тому +1

      @@Tacoburito Pretty old, but what part?

  • @philippegregoire6151
    @philippegregoire6151 5 років тому +5

    i have a problem with the collision

  • @thijs3135
    @thijs3135 6 років тому +4

    Please can you go on with the series to add lika a random enemy spawner or attacking

    • @uheartbeast
      @uheartbeast  6 років тому +1

      Check out the GMS 1.4 series. Most of the stuff like enemies and pathing can be easily converted to GMS 2: ua-cam.com/play/PL9FzW-m48fn2gQVYFxDzq4cz2A4uGWusx.html

    • @thijs3135
      @thijs3135 6 років тому

      Thanks

    • @narulan9325
      @narulan9325 6 років тому

      HeartBeast Hey,can you make shadow tutorial for gm studio 1.4.x?
      Yeah , I know I am using such old version,but I started random generation project, and modified it so much, I can't export it to gms 2.
      Anyway I hope you will reply

  • @superspeed2378
    @superspeed2378 4 роки тому

    When using the GMS 1.4 tutorial to add enemies to the game, they spawn inside the walls, which I'm assuming is because the actual tiles we're using in this version are the walls not the floor.
    Where would you place the randomly generated enemies code in order to make sure they spawn outside the tiles/wall?

    • @于致远
      @于致远 4 роки тому

      just encounter the same problem. Have you fixed it yet?

    • @superspeed2378
      @superspeed2378 4 роки тому

      @@于致远 I ended up putting the "Spawn Some Enemies" code inside Heartbeast's "Create Wall Tiles" code, underneath the part that says "if (grid_[# _x, _y] == Floor)" and it worked.

    • @于致远
      @于致远 4 роки тому

      @@superspeed2378 Thanks for your reply. I did the same thing, which created a object "enemySpawn" and then paste "if (grid_[# _x, _y] == Floor) " in it. But the enemies can still spawn in the wall. I just cannot fix it.

    • @DANGGOOSE
      @DANGGOOSE 4 роки тому

      @@于致远 any update on if you fixed this error?

  • @larryteslaspacexboringlawr739
    @larryteslaspacexboringlawr739 6 років тому

    thank you for gamemaker video

  • @theorigainalbuleblur
    @theorigainalbuleblur 6 років тому

    thanks for the tutorial man, but can you do one that lets the player collide with the portal at the end of the level to add a new room please

  • @cungalunga8971
    @cungalunga8971 6 років тому

    Love your vids! Keep it up!

  • @popooppop
    @popooppop 5 років тому +1

    This is the cool!)
    This is how "Soul king"
    Thank )

  • @thisyoutubeishaunted
    @thisyoutubeishaunted 6 років тому +1

    Does anyone know if it's possible to alter the player movement so they move more akin to a platformer? (ie. jump to move up, gravity that keeps them against the bottom wall)...
    I have a feeling this shouldn't be too difficult but I just can't get my head around it (because of all the grid_place_meeting stuff, since I'm used to doing place_meeting(Solid) related code)...

  • @lucasramos6580
    @lucasramos6580 3 роки тому

    ok so i adding this to the RPG begginer series of gamemaker 1 that he did and...
    i trying to convert this to work with the player that i already have but...
    the collision is not working and the only major thing that i changed is trying to set hspd and vspd to 0 but is not working
    so if anyone can reformulate the code to work with the rpg begginer series and send me it will be of great help
    PS:english is not my first language soo....
    sorry for anything i spelled wrong

  • @cliffordlucien1826
    @cliffordlucien1826 6 років тому

    would it work for platformers?

  • @peremoyaserra2749
    @peremoyaserra2749 6 років тому

    The link to the other video doesen't work for me

  • @nathan08085
    @nathan08085 6 років тому

    These are so cool
    If only I could upgrade from 1.x

  • @laurencio1785
    @laurencio1785 2 роки тому

    ice on cup bro

  • @matthewlouwrier9973
    @matthewlouwrier9973 6 років тому +1

    honestly i prefer game maker 1.4

  • @thedogshop7561
    @thedogshop7561 6 років тому

    Fperst