1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

Does 'speed' equate to 'hspeed' and 'vspeed'

Discussion in 'Programming' started by Halph-Price, Nov 25, 2017.

  1. Halph-Price

    Halph-Price Member

    Joined:
    Mar 20, 2017
    Posts:
    42
    Just wondering if to change speed and angle does it translate to the hspeed and vspeed variables, or is it separate. Either way, anyone got any good collision tips for overhead games?
     
  2. Halph-Price

    Halph-Price Member

    Joined:
    Mar 20, 2017
    Posts:
    42
    I am lost.
     
    Last edited: Nov 25, 2017
  3. JFitch

    JFitch Member

    Joined:
    Sep 28, 2016
    Posts:
    428
    If you change hspeed and vspeed, speed and direction will automatically change to match, and vice versa.
     
  4. Halph-Price

    Halph-Price Member

    Joined:
    Mar 20, 2017
    Posts:
    42
    Okay, thanks a lot, documentation doesn't really mention it, but it seems likely... hard to know what's related.
     
  5. kburkhart84

    kburkhart84 Firehammer Games

    Joined:
    Jun 26, 2016
    Posts:
    467
    That's actually kind of a good part about Gamemaker...the majority of those automatic object variables update each other when you change them. The only exceptions to those that I've found are when you are using the Box2d physics(and you actually get a separate set of vars for that), and when you use paths for movement.

    About collision tips for overhead games...I'd use a lot of circles for collision masks. You don't want to use pixel perfect masks because things can easily get stuck. Note that this actually applies to almost all games.
     
    Wraithious likes this.
  6. Halph-Price

    Halph-Price Member

    Joined:
    Mar 20, 2017
    Posts:
    42
    I am using paths in the game tho, and it does seems like speed and such is kind of useless in this operation.
     
  7. Tsa05

    Tsa05 Member

    Joined:
    Jun 21, 2016
    Posts:
    560
    Speed is the speed that your object is moving.
    Hspeed is the speed that your object is going, horizontally.
    Vspeed is the speed that your object is going, vertically.

    Those are 3 very different things, which can be related via direction.

    In GameMaker (and most other things), the default direction (zero degrees) is the equivalent of "straight to the right." And then you proceed counter-clockwise. So 45 degrees is up and to the right, 90 degrees is straight up, 135 degrees is up and to the left, 180 degrees is straight to the left, and so on, until 360 degrees (a complete circle) points in the same direction as 0 degrees.

    Suppose that you have an object moving diagonally at 45 degrees--up and to the right--at a speed of 5 pixels per step. The object's speed is 5. The object is moving horizontally and vertically at the same time. It's moving less than 5 pixels to the right, and less then 5 pixels straight up. But the combination of movement in the 2 directions results in 5 pixels diagonally. If you change the speed, the hspeed and vspeed will update. If you change the vspeed or hspeed, the speed will update. GameMaker links these together.
     
  8. Halph-Price

    Halph-Price Member

    Joined:
    Mar 20, 2017
    Posts:
    42
    unless you're moving by xy position or motion planning, because one is like teleporting and the other is an isolated function it seems.
     
  9. kburkhart84

    kburkhart84 Firehammer Games

    Joined:
    Jun 26, 2016
    Posts:
    467
    Yeah, you would be right about that. I'm understanding you can change how fast the object moves along the path, but of course it won't work the same. If you need to know speeds in pixel units when things move along the path, you can always store the current x/y into variables, and in the step event compare the previous x/y with the current x/y. You can get distance and direction this way for if you need it for something.
     
  10. buu342

    buu342 Member

    Joined:
    Nov 26, 2017
    Posts:
    8
    Here's a quick diagram I made of how hspeed/vspeed is calculated in Game Maker. It's all essentially Pythagoras' theorem, which hopefully everyone has done a bit of.

    [​IMG]
     
    Halph-Price and NoobsWeStand like this.
  11. Halph-Price

    Halph-Price Member

    Joined:
    Mar 20, 2017
    Posts:
    42
    GMS2 actually has a xprevious and yprevious variable that is set before the start of the 'begin step event'.
     
  12. buu342

    buu342 Member

    Joined:
    Nov 26, 2017
    Posts:
    8
    It exists in GM 5, one of the first versions of game maker sold, as well. It's a rather old and extremely useful function :D
     

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