Це відео не доступне.
Перепрошуємо.

How to Move and Collide in GameMaker

Поділитися
Вставка
  • Опубліковано 7 чер 2023
  • This tutorial teaches you the easiest way to move in GameMaker, with proper collisions, and it only takes a few minutes to set up.
    Get the sprites: yoyo-www-cms.s...
    Read the blog: gamemaker.io/e...
    Need help? Join our Discord: / discord

КОМЕНТАРІ • 134

  • @GameMakerEngine
    @GameMakerEngine  Рік тому +7

    This tutorial works for GameMaker 2023.1 and newer. If you use an older version of GameMaker, check out:
    👾Platformer: ua-cam.com/video/XaaLgOOFxAw/v-deo.html
    👾Top Down: ua-cam.com/video/oqYyD4KB7pw/v-deo.html

  • @ollie_r8162
    @ollie_r8162 Рік тому +101

    The function to replace 70% of game maker tutorials.

  • @entinoo
    @entinoo Рік тому +44

    In case anyone's having problems with moving - try setting both the "Max X Movement" and the "Max Y Movement" in Move and Collide to "-1". This should fix the issue. Shoutout to Mimpy for figuring this out :)

    • @GameMakerEngine
      @GameMakerEngine  Рік тому +8

      Thank you and Mimpy again!

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

      do you know how to do that in code?

    • @hairo4242
      @hairo4242 8 місяців тому +4

      they were set to -1 and my dumbass turned them to 0 because of tutorial well thanks for this!

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

      @@hairo4242
      Where

    • @tacodragon3421
      @tacodragon3421 3 місяці тому +1

      @@hairo4242 same, thought it was suppsoed to be 0 before even testing it

  • @keokluck
    @keokluck 3 місяці тому +11

    i did everything exactly the same, but i cannot make it past the debugger.

  • @Slowman_CH
    @Slowman_CH Рік тому +9

    This is very useful, I've once looked for a tutorial about this, but I'm at a loss, with this function I will be greatly helped

  • @craigpoltenovage9148
    @craigpoltenovage9148 8 місяців тому +4

    infinitely more helpful than the gamemaker code videos. Thank you man.

  • @Scarabola
    @Scarabola Рік тому +17

    Finally, after all these years.... the horror...

  • @Benjamin-vx2ot
    @Benjamin-vx2ot 9 місяців тому +6

    so cool that you show BOTH ways GML and GMV,, just awesome!

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

      Its gamemaker oficial chanell

    • @Benjamin-vx2ot
      @Benjamin-vx2ot 7 місяців тому

      @@phel7369 yes, correct 😄

  • @flameintheheart7548
    @flameintheheart7548 7 місяців тому +5

    In case anyone else made the same mistake as I did, make sure when your player object is not moving, that you didn't overlap their frame into the wall object frame or it will not move at all. I simply dragged it out of the overlapping frame and it could move.

    • @Mel-eg4xs
      @Mel-eg4xs 5 місяців тому +1

      Thank you so so much! 🙏
      That just solved the problem for me after I`ve tried so many different codes from different tutorials and nothing worked.

    • @bartoszgie9312
      @bartoszgie9312 7 днів тому +1

      thank you

  • @CairoWax
    @CairoWax Рік тому +9

    AFTER A FEW HOURS OF TRYING TO DO IT BY WATCHING OTHER TUTORIALS- I FINALLY DID IT..

  • @smokinjoe9415
    @smokinjoe9415 3 місяці тому +4

    Why are you not using a unit vector to calculate proper movement? The way you are moving will make you move faster diagonally, so it is not the correct way to do it at all. Why not explain the proper way to do movement? For example:
    // Get player input
    var keyLeft = keyboard_check(vk_left) || keyboard_check(ord("A"));
    var keyRight = keyboard_check(vk_right) || keyboard_check(ord("D"));
    var keyUp = keyboard_check(vk_up) || keyboard_check(ord("W"));
    var keyDown = keyboard_check(vk_down) || keyboard_check(ord("S"));
    // Determine input direction and magnitude
    var inputDirection = point_direction(0,0,keyRight-keyLeft,keyDown-keyUp);
    var inputMagnitude = (keyRight-keyLeft != 0) || (keyDown-keyUp != 0);
    // Calculate our movement vector (the proper way so that diagonal movement does not exceed our walk speed!)
    hSpeed = lengthdir_x(inputMagnitude * speedWalk, inputDirection);
    vSpeed = lengthdir_y(inputMagnitude * speedWalk, inputDirection);
    // Move the character
    x += hSpeed
    y += vSpeed;

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

    Das hat mir sehr geholfen.
    Genau das was ich gebraucht habe 🙏🙏🤓

  • @xcalicojack
    @xcalicojack 7 місяців тому +2

    I just have a sprite and a white background. sprite is not moving after copying this video. any ideas?

  • @Jordnscot
    @Jordnscot 10 місяців тому +3

    Hey👋how can i apply the collison code to work properly with movement that has acceration and decceration? im moving faster at angle then if i were moving straight.

  • @beter_dan_mors
    @beter_dan_mors 9 місяців тому +4

    Help, when I run into the walls i don't collide but I just slow down while I rub trough them. Does someone know how to fix this?

  • @fruitsalad2379
    @fruitsalad2379 9 місяців тому +5

    Two questions
    How to make this work with tileset collision
    How to make this work with advanced 8-way movement (the movement in the manual that prevents faster movement via diagonal movement)

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

      dont do tileset colision, do 1 obj to have the colision and use it everywhere u want to, to make it invisible just do the step code image_alpha = 0;

  • @SalemRose503
    @SalemRose503 3 місяці тому +1

    1:42 Is... Is that really the visual/not-code version? How is that not code? I am so lost...

    • @DieserEineee
      @DieserEineee 3 дні тому

      The left side is visual coding and the right side is just text coding code lol

  • @JustBasicAnimator
    @JustBasicAnimator 11 місяців тому +2

    best tutorial i have ever seen now i know how to code thx

  • @kodlamavetasarım
    @kodlamavetasarım 4 місяці тому +1

    Thanks great video

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

    Move_and_collide must be one of the most convenient functions when it comes to movement

  • @TwistedDyno740
    @TwistedDyno740 10 місяців тому +2

    idk why but its not working, can someone help me?

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

    move_and_collide doesn't appear. What should i do?

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

    would be great if this went into more depth on how to pair this with actual platformer movement like jumping and gravity so you're not just floating in space. As is, it seems it would be better for top down style movement. I'm figuring out myself to see how it also works with place_meeting collision and what not. Not really complaining, just stating it would have been nice to see more out of this like your other tutorials. Thanks for getting the gears turning on how to use this function!

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

      ye this is like a survival style game, but would work the same when in platformer i think, just look up platformer tutorial

  • @shockingevacuation8995
    @shockingevacuation8995 11 місяців тому +3

    is anyone encountering an issue where theyre following all the same steps, but when it comes time to run the game they keep getting the same error?
    "Object: obj_player Event: Step at line 6: Cannot set a constant ("right") to a value
    Object: obj_player Event: Step at line 13: Cannot set a constant ("left") to a value"
    im using gml visual

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

      Yes bruh 💀

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

      dude..... this fix is needed asap

    • @FaithGames-j3d
      @FaithGames-j3d 6 місяців тому +1

      i think its cuz you have to set the var as _right not right, like "right" is already a preset variable with a constant value

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

    How would I make this work but with tile maps instead of objects? and only colliding with the actual pixels of the tiles instead of the whole square?

  • @earbitter
    @earbitter 9 днів тому

    I'm building a new game (first one) and followed this guide, but when my player object hits the right wall, I can only get off of it by pressing left and down at the same time, and I can't move up at all. On the flip side, the left wall also traps my player, and I can only move away from it by pressing up and right at the same time.

    • @GameMakerEngine
      @GameMakerEngine  9 днів тому

      💪 good luck on the first game! For the coding help the best place to go is the GM Community Forum or Discord
      Forum: forum.gamemaker.io/index.php
      Discord: discord.com/invite/gamemaker

  • @_FurryOwO_
    @_FurryOwO_ 3 місяці тому +1

    How to stop character animation when he hits the wall?

  • @clayton_games
    @clayton_games 9 місяців тому +2

    Why am I getting stuck in walls?

  • @BenjaminBausch
    @BenjaminBausch 25 днів тому

    Life Saver

  • @ammsaas2838
    @ammsaas2838 26 днів тому

    I did this and now it just slows down when the player hits the wall, it doesnt stop. someone help

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

    I still have issues with 1 pixel gap. how do i "fix this".

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

      Change your character collision box to one pixel smaller

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

    I have an odd issue with the corners, I just go straight through them - or infact any object I create after the main wall my character ignores collision.

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

    How do you make diagonal movement same speed as moving into just 1 direction??

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

    is there any way to get this to work for multiple objects ¿ when i just add another object to move and collide it restricts me from moving , and when i copy and paste the move and collide it doubles my speed and i walk like sludge right through my objects . i cant create a new set because it just merges with the already existing set . am i missing something ¿
    edit : figured while im at it id mention there are some points on diagonal walls where my character gets stuck , but i can still wiggle my way out if i turn back and forth and move up or down

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

    When the movement speed is a decimal point, the screen shakes as the player moves.
    How do I solve this part?

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

      Lerp the camera following the object. Uses linear interpolation for the movement of the camera/camera object.

  • @sovegaard
    @sovegaard 20 днів тому

    Why is my object automatically going to the right?

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

    THANK YOU SO MUCH I REALLY APPRITIATE IT

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

      YOU'RE MOST WELCOME :)

    • @joyw4127
      @joyw4127 2 місяці тому +1

      funny😂🤣🤣🤣🤣🤣🤣🤣🤣

  • @alejandronieto8649
    @alejandronieto8649 9 місяців тому

    What's the diference betwen this and use de colisión event for detect collisions with walls?

  • @user-wk5km7yv9j
    @user-wk5km7yv9j Рік тому +4

    Does anyone know how to make it so that the diagonal angles go the same speed as the horizontal and vertical?

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

      You can do that by calculating the direction of movement using point_direction(0, 0, x_input, y_input). Then put that into lengthdir_x() and lengthdir_y() as the direction, along with a speed as the length, and add the results to the X and Y variables respectively. This gives you a uniform speed in whatever direction you enter.

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

    I'm still not able to move, even tho i did everything step by step. Is there something wrong?

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

    I got movement down but I can’t get the collision to work, I walk through walls- help?

  • @PlayerOG-S
    @PlayerOG-S 4 місяці тому

    How can I use this method in a platform game?

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

    2:29 I have this written as shown it’s not working can someone help me

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

    Let’s go!

  • @Flyd22
    @Flyd22 9 місяців тому

    im making it it code and whenever i try to move it doesnt work

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

    Hi like btw im from Indonesia but I have a question a GameMaker Can't create Game Genre simulators???

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

    didnt work, can someone help me

  • @RiotRebirth
    @RiotRebirth 9 місяців тому

    How do you make this work with tilesets please?

  • @WonderSealYT
    @WonderSealYT Місяць тому

    I can’t get my sprite to spawn

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

    im not sure what i did wrong but it isnt working

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

    my guy goes to the right really fast and i cant control him, please help

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

      the name of your variable for the characters walk speed is called "speed" make sure it is not green. try " _speed". Speed is already a prebuilt variable with constant value. So it is going to do some weird things.

    • @pixeltree13
      @pixeltree13 3 дні тому

      ​@@bombardier1588I was so lost on the same issue, thanks man 👍

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

    how do i make it so the player can,t move up and down and just left and right because move and collide doesn,t want to work that way

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

      Did you get it?

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

      @@GameMakerEngine i tried but it needs 3 arguments and it just doesn,t work i tried erasing var up and var down but then it doesn,t work

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

      @@_Vonos_ Sorry it took a while to get back to you. You could try set the y component of your movement to zero, or you could follow the 5 min platformer tutorial: ua-cam.com/video/-5sBIUiutAk/v-deo.html

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

      @@GameMakerEngine thx

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

    What if you have multiple obj with collision.
    Do you repeat move_and_collide and add the different obj
    Or
    You can use comma and continue adding obj in same?

    • @Gamer-wj4qv
      @Gamer-wj4qv 11 місяців тому

      Those objects should inherit from one object and then you use move_and_collide on that object.

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

      @@Gamer-wj4qv I meant for different sprite in different object. Do you use move_and_collide (........, obj_1, obj_2, obj_3) to put different objects to get collision in one code or do you have to copy paste and just replace obj_1 with obj_2 and so on?
      also I am pretty much learning from scratch so I have no idea. Just practicing as much as i can in free time.

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

      I've run into the same issue

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

      Yeah me too, if anybody has figured this out please let us know❤

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

      @@samsungphone1326 look up a guide for "object collision parents" in gamemaker if you haven't figured it out yet.

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

    So you have to have a Wall object in the room to move!

  • @scarcekoi
    @scarcekoi Місяць тому

    No tutorials that show how to move rooms work with this.

  • @Kserks96
    @Kserks96 9 місяців тому

    When i plress LMB+Alt it just moves my screen around

    • @Godpuncher420
      @Godpuncher420 6 місяців тому +1

      Had this same issue and I was getting extremely frustrated that nobody mentioned it. In case you haven't figured it out, Game Maker 2 has a "Laptop mode" that makes left-alt and right-alt have different functions. You can just use your right alt key. Or, to turn off laptop mode, the button for it is the laptop icon at the top (down-right of the "Source Control" menu on the menu bar)

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

    How do I make it work with multiple objects

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

      read fruitrsalad’s comment

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

    followed the tutorial exactly but when I load the game it will not move the character

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

      There seems to have been an update. Try setting both the "Max X Movement" and the "Max Y Movement" in Move and Collide to "-1". That fixed the issue for me!

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

      @@entinoo thanks i'll try that

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

    Does this work for older versions?

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

    i cant move up or down

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

    i did everything the same but my player wont move

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

      There seems to have been an update. Try setting both the "Max X Movement" and the "Max Y Movement" in Move and Collide to "-1". That fixed it for me!

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

    when i add other object then i can only move uo and down idk why can you help me?

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

      The best place to go is the GM community forum or Discord
      Forum: forum.gamemaker.io/index.php
      Discord: discord.com/invite/gamemaker

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

    It crashed

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

    Can you make a version for 2d platformers?

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

      Check the channel, the previous video is exactly that

  • @MiguelAngelValdepenaDelgado

    oh !!!

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

    Move and collide???? Is this new??

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

      Sprites have been moving and colliding since before Seiklus, but this tutorial just shows off the newest fastest way to crash into walls.

  • @user-nn4ji8nk7y
    @user-nn4ji8nk7y 7 місяців тому +1

    Sorry didn't work for me idk

  • @misterbrick2031
    @misterbrick2031 18 днів тому

    Is bro speaking france or english and is bro usain bolt💀

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

    perdin sime sirvio

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

    It didn’t work 😢

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

    Mine does not run when I use this code

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

      Oh, try using the debugger: ua-cam.com/video/rqSRmFT1I-U/v-deo.html

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

      Another option would be to post in the community forum or Discord. The community are really helpful there:
      Forum: forum.gamemaker.io/index.php
      Discord: discord.com/invite/gamemaker

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

    Didn’t work

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

    I can’t fucking accept your cookies why?

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

    what about npcs moving?

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

      Hey, great question.
      Here's a tutorial on how to make NPC's choose directions: ua-cam.com/video/8qUg_2CvD0k/v-deo.html
      Here's a forum post about random movement: forum.gamemaker.io/index.php?threads/how-i-can-create-npc-movement-like-pokemon-red.21160/

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

    no me sirvio tu momo

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

    player wont move

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

    Didn't work for me

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

      What issue are you facing? Make sure you have updated to the latest version of GameMaker.

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

    how do i fix this:
    ############################################################################################
    ERROR in
    action number 1
    of Step Event0
    for object obj_player:
    Variable .right(100009, -2147483648) not set before reading it.
    at gml_Object_obj_player_Step_0 (line 34) - var _xinput = right - left;
    ############################################################################################
    gml_Object_obj_player_Step_0 (line 34)

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

    how to fix
    ___________________________________________
    ############################################################################################
    ERROR in
    action number 1
    of Step Event0
    for object obj_player:
    Variable .vkright(100004, -2147483648) not set before reading it.
    at gml_Object_obj_player_Step_0 (line 1) - var _right = keyboard_check(vkright);
    ############################################################################################
    gml_Object_obj_player_Step_0 (line 1)