How to move diagonal correctly [Game Maker Studio 2 | Basics]

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

КОМЕНТАРІ • 55

  • @ShaneTheCreep
    @ShaneTheCreep 6 місяців тому +5

    I only needed the number 0.707 but this video was very helpful :)

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

      :D, well you got what you were looking for. That is all I need to hear.

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

    Thank you for the toturial!
    Pretty proud how i was able to create what i have on mind using different toturials.
    An 8 directional movement of which accelerates until you meet the max speed.

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

      Basicly a 2d top down shooter game in which counter strafing can be used as a mechanic.
      Gun accuracy determined by player speed.

    • @1upIndie
      @1upIndie  Рік тому

      You are welcome. I am not sure what you are trying to tell me here.

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

      @@1upIndie don't worry about it just keep making great tutorials like this!

  • @razmatazz9310
    @razmatazz9310 2 роки тому +2

    Damn, you came back with a bang! Good to see you back in action.

    • @1upIndie
      @1upIndie  2 роки тому

      Well, that is some small bang :D, but thanks mate.

  • @RC-go2kl
    @RC-go2kl 2 роки тому +4

    Never really understood why diagonal was faster, but yea, this clears it up

    • @foxbastergames1383
      @foxbastergames1383 9 місяців тому +1

      force+force=bigger force

    • @seryal
      @seryal 24 дні тому +1

      @@foxbastergames1383 a^2 + b^2 = c^2

  • @jacobc9221
    @jacobc9221 4 місяці тому +2

    The most helpful part of this were those last two lines. I was trying to use motion_add and motion_set XD

  • @eunit08
    @eunit08 2 роки тому +2

    This is going to help a lot of people. Great job

    • @1upIndie
      @1upIndie  2 роки тому +1

      Yeah, let's hope it does help out the community!

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

      @@1upIndie i needed that in a previous project I started years ago. I lost thr file when my previous laptop crashed. I make backups now

  • @313Blc
    @313Blc Рік тому +3

    for vsp and hsp (diagonals) must multiply all with SpeedNormal

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

    Thanks for this video, I actually did this before but the way I did it was so bad cause I checked if the player was holding down 2 buttons to move diagonally ex. if (left) && (down) and obviously I had to do this for the other combinations which was clearly bad xD Although I don't know if its just me but the example game you have in the video looks natural with the diagonal movement reduction but obviously really sped up going diagonal but in my game with only 5 for my speed looks natural moving diagonal but like a sudden turtle like slowdown when moving diagonal with the speed compensation which looks really unnatural. I have a dash in my game though which for sure looks unnaturally sped up going diagonal versus straight so I only did the diagonal compensation when dashing and looks really nice 😁. Oh yeh I've seen some of your videos here and there and really enjoy your tutorial style. Seems chill and straight to the point with already having your code there to copy paste and explain it briefly. Subbed a few days ago, Keep up the great work 👍

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

      Thanks a lot for subbing! Hope you get your times worth on my small channel.

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

    Thanks man

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

    Thank you

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

      Youre are more the welcome!

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

    When I use this my character is super shaky when going diagonally

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

      Hm, no idea how to help you out here.

  • @AIG0801
    @AIG0801 2 роки тому +3

    Thank you for consistent uploads! Do you think you could make a tutorial covering fall damage in a 2D platformer?

    • @1upIndie
      @1upIndie  2 роки тому

      Hm, that would need to be tied to a specific jump/gravity state machine. Fall damage is just a timer that is running down when you are in the state of "being in the air" (no collison below you is happening), so you run it down and when it hits a specific mark you damage the player (and of course you reset the timer when you land each time).

    • @1upIndie
      @1upIndie  2 роки тому

      @Niel There is concept that is very popular for this kind of thing. It is called a state machine. Shaun spalding explains it pretty good here. Hope that helps.
      ua-cam.com/video/yfFzz9mZkU4/v-deo.html

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

    this is not hate or anything, but I am the only who feels like the movement is actually slower with .707 as multiplier?

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

      Hm, maybe it looks like that. Mathematically it should be more or less on par. Dunno to be honest.

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

      @@1upIndie ok, might be just my eyea

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

    nice! how about one using analogue/stick control instead of keys?

    • @1upIndie
      @1upIndie  Рік тому

      I have 3 videos (or other channels cover that too) on that, simply search for gamepad, where you can find what you are looking for.

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

    Thank you!!! but how would I add a separate sprite when a diagonal is occurring.

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

      Image angle might help with that. Maybe you could try putting
      image_angle = direction;
      inside of the step events

  • @NoahNCopeland
    @NoahNCopeland 2 роки тому +2

    0.707 being the cosine of 45 degrees, yeah?

    • @1upIndie
      @1upIndie  2 роки тому +1

      Yup.

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

      √2÷2 = cos(45)

    • @aaronmaldonado6562
      @aaronmaldonado6562 2 роки тому +3

      Teorema de Pitágoras:
      a²+b²=c²
      En este caso lo ocupamos de la siguiente manera:
      √(a² + b²) = c
      Entonces para este caso en particular "a" es la velocidad horizontal (1 pixel) y "b" es la velocidad vertical (1 pixel), entonces si lo imaginás como un triángulo rectángulo "c" es la hipotenusa de ese triángulo rectángulo.
      Pero la mitad de la hipotenusa correspondería a la velocidad diagonal (0.7071067811865):
      √(1² + 1²) = 1.4142135623730
      1.4142135623730 ÷ 2 = 0.7071067811865
      No sé si Game Maker te permite calcularlo con alguna función incorporada, pero espero que se entienda.
      Este video es genial porque es muy sencillo, literalmente podrías hacerlo de esa manera, porque en este caso la diagonal siempre será de 45° por lo tanto la velocidad diagonal es siempre su coseno.

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

      @@aaronmaldonado6562muy buena explicacion, muchas gracias!

  • @mondo-od8fo
    @mondo-od8fo 5 місяців тому +1

    za ap and down moovement

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

      Ja, zat iz korrekt

  • @1upIndie
    @1upIndie  2 роки тому +5

    var SpeedNormal = 1.5;
    var SpeedDiagonal = SpeedNormal * SpeedNormal ;
    // get input for the keyboard
    var left = keyboard_check(vk_left);
    var right = keyboard_check(vk_right);
    var up = keyboard_check(vk_up);
    var down = keyboard_check(vk_down);
    // seperate into horizontal and vertical movement
    var hor = (right - left); // -1 0 1
    var vertical = (down - up); // -1 0 1

    // endresult to add to current x,y position
    var hsp = 0;
    var vsp = 0;
    // diagonal
    if (hor != 0 and vertical != 0 ){
    hsp = hor * SpeedDiagonal;
    vsp = vertical * SpeedDiagonal;

    }
    // no input or only pressed left/right or up down? -> then move normally
    else {

    hsp = hor * SpeedNormal;
    vsp = vertical * SpeedNormal;

    }

    //apply! to move the player
    x += hsp;
    y += vsp;

    • @bobelpatron4280
      @bobelpatron4280 2 роки тому +2

      Why we need to multiply the speed by 0.707?

    • @1upIndie
      @1upIndie  2 роки тому +1

      ​@@bobelpatron4280 This value (0.707) is set a multiplication value to normalize/even out the double speed that you get if you use for horizontal and vertical the same speed value (which is shown in the video).
      If you really really want to know why, well you can research Pythagorean Theorem and will get a rougly a multiplication value of 0.7 also. 0.707 is a bit more accurate, but not really world breaking if you "only" use 0.7.
      Hope that helps

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

      @@1upIndie Thank you

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

      You are an awesome guy ♥️

    • @add-iv
      @add-iv 2 роки тому

      @@bobelpatron4280 sin45° (and cos45°) is about 0.707, if you use the pythagorean theorem it will get too complicated in case you want to move at a different angle. For that you can just do sin(angle) for y speed and cos(angle) for x speed