don't click here

How the Drop Dash works in Mania

Discussion in 'Engineering & Reverse Engineering' started by MainMemory, Nov 25, 2017.

  1. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,785
    365
    63
    SonLVL

    Now, while I haven't actually played any hacks or fangames that have the Drop Dash in them, I have a feeling that few if any of them are implementing it in exactly the same way that Sonic Mania does, simply because of how complex the calculations actually are. This post is meant to explain the mechanics and physics behind the Drop Dash, I will not give you ASM code to paste into your hack with no effort. At the bottom of the post, I have a Sonic 2 ROM with Drop Dash implemented according to this information as an example.

    This first part of code runs when Sonic is jumping. If the jump button is pressed, the jump ability flag is 1 (meaning you can use an ability), Sonic does not have an elemental shield power, and the moveset is set to Mania, the jump ability flag is set to 2 to signify the initiation of a Drop Dash. Then, if the jump ability flag is greater than 1 and the jump button is held, the flag's value is incremented each frame until the result is greater than 21 (meaning a 20-frame waiting period), at which point the Drop Dash is properly started, playing the sound effect, changing Sonic's animation, and changing his movement routine (you may use a flag instead).
    Now, if the jump button is released before Sonic hits the ground, the Drop Dash is cancelled, restoring the normal rolling sprites and putting him in a falling state and setting the jump ability flag to 0 so he cannot use abilities.
    When Sonic hits the ground with a Drop Dash charged, first the game performs the regular landing speed calculations so his ground speed is set according to X and Y speed in the air and the slope of the ground. The game checks if you are holding Left or Right, and sets Sonic's current direction to the direction you are holding.
    Then, it sets two variables depending on whether you are currently Super Sonic, which I will call dashspeed and maxspeed. Sonic Mania uses 32-bit speed values, but for convenience I will use 16-bit values with decimal versions in parentheses. If you are not Super, dashspeed is set to $800 (8.0) and maxspeed is set to $C00 (12.0); if you are Super, dashspeed is set to $C00 (12.0) and maxspeed is set to $D00 (13.0).
    The dashspeed and maxspeed values and the comparisons in the next lines are all negated if your direction is left, but otherwise the math is the same as when your direction is right. If your X speed (in the air) is greater than or equal to 0, your ground speed (inertia) is divided by four (>> 2) and added to the dashspeed, then it is capped to maxspeed. Otherwise, if your angle is not 0 (on a slope), your ground speed (which is moving backwards because the first check failed) is cut in half and added to the dashspeed, resulting in a slower than normal dash. If you're moving backwards on flat ground, your ground speed is simply set to dashspeed.

    Here's some code directly from the game for when you hit the ground while charging a Drop Dash:
    Code (Text):
    1.     v0->JumpAbilityFlag = 0;
    2.     if ( v0->RightHeld == 1 )
    3.       v0->Direction = 0;
    4.     if ( v0->LeftHeld == 1 )
    5.       v0->Direction = 1;
    6.     if ( v0->SuperMode == 2 )
    7.     {
    8.       dashspeed = 0xC0000;
    9.       maxspeed = 0xD0000;
    10.     }
    11.     else
    12.     {
    13.       dashspeed = 0x80000;
    14.       maxspeed = 0xC0000;
    15.     }
    16.     if ( v0->Direction )
    17.     {
    18.       if ( v0->XSpeed <= 0 )
    19.       {
    20.         v6 = -maxspeed;
    21.         v7 = (v0->GSpeed >> 2) - dashspeed;
    22.         v0->GSpeed = v7;
    23.         if ( v7 < v6 )
    24.           v0->GSpeed = v6;
    25.         goto LABEL_25;
    26.       }
    27.       if ( v0->GroundAngle )
    28.       {
    29.         v0->GSpeed = (v0->GSpeed >> 1) - dashspeed;
    30.         goto LABEL_25;
    31.       }
    32.       dashspeed = -dashspeed;
    33.     }
    34.     else
    35.     {
    36.       if ( v0->XSpeed >= 0 )
    37.       {
    38.         v5 = dashspeed + (v0->GSpeed >> 2);
    39.         v0->GSpeed = v5;
    40.         if ( v5 > maxspeed )
    41.           v0->GSpeed = maxspeed;
    42.         goto LABEL_25;
    43.       }
    44.       if ( v0->GroundAngle )
    45.       {
    46.         v0->GSpeed = dashspeed + (v0->GSpeed >> 1);
    47.         goto LABEL_25;
    48.       }
    49.     }
    50.     v0->GSpeed = dashspeed;
    51. LABEL_25:
    52.  
    And here's the Sonic 2 with Drop Dash ROM: http://mm.reimuhakurei.net/misc/S2DropDash.zip
    I've also removed the air speed cap and disabled the rolljump behavior.
     
    Last edited: Feb 14, 2023
  2. Zphase

    Zphase

    Member
    14
    1
    3
    I played to Metropolis Zone and the drop dash in Sonic 2 is a lot of fun, thanks!
    I guess you mentioned this is an example.. but any plans to give Super Sonic a drop dash sprite?
     
  3. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,785
    365
    63
    SonLVL
    Whoops, two of Sonic's animations are missing from the end of Super Sonic's list. I've fixed it now.
     
  4. Crappy Blue

    Crappy Blue

    Knuckles' Chaotix is a perfect game with no flaws Member
    I think this is the biggest issue with prior attempts at coding the drop dash in rom hacks. While there are a lot of factors of its functions in Mania that go into why it's fun (and habit-forming) to use, the ability to control your air movement from a drop dash jump and even turn yourself around to drop dash in the other direction makes a huge difference in its utility. To my knowledge, every hack submitted to the hacking contest or expo this year that added the drop dash missed this bit, and it just makes it... less fun.
     
  5. RetroKoH

    RetroKoH

    Member
    1,699
    70
    28
    S1Fixed: A successor to ReadySonic
    I completely agree with this. Personally I didn't care for seeing that control lock removed back when they did it in CD... but I get why double jumps in Sonic 3 essentially negated it. It made sense. Makes just as much sense with the drop dash.
     
  6. Okamikurainya

    Okamikurainya

    Member
    232
    15
    18
    Somewhere in Africa
    Relearning everything I've forgotten.
    Also, can't forget that while Super the DropDash causes the screen to shake as well as playing the Peelout release sound rather than the normal one. That may not be related to the physical effects but it's still a little thing that adds to making it feel authentic.

    Thanks! This guide was a massive help for me, until I read this I assumed that the frame timer was actually a detection for a downwards yspeed. :v:
     
  7. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,785
    365
    63
    SonLVL
    Since it's related to the topic, I'll just put this here: Drop Dash in S3K.
     
    Last edited: Feb 14, 2023
  8. EnderWaffle

    EnderWaffle

    Ghostly Friend Member
    Even better! Now the next step up is Drop Dash in SA1 *runs*
    I got all the way to Launch Base, and I gotta say, this is a much better recreation of the original style than the handful other hacks I've seen with the Drop Dash, which just give you a chargeable Spin Dash in each jump. Bravo!
     
  9. AeroGP

    AeroGP

    Member
    130
    1
    18
    Los Angeles, CA
    Sonic for GameMaker: Studio
    Hey, late response but I wanted something clarified:

    That sounds like it would be faster than normal, since adding half of something to something else is greater than adding only a fourth of it, or adding nothing at all. I also notice that this speed addition is not capped by max_speed the way the first check is. If slowing the dash down was the intent, I believe this needs to be re-evaluated ...

    EDIT: Nevermind. I realized that the speed would negative in the second case, so it would subtract from the dash speed, not add to it. Silly me.
     
  10. Caverns 4

    Caverns 4

    Member
    346
    0
    16
    Sonic: Retold
    This is impressive and helpful, nice code hunting!

    Now just to get it working in my hack. Which is a chore in itself.
     
  11. Zeoinx

    Zeoinx

    Member
    43
    3
    8
    I always assumed the drop dash acting in a simlar manner to that of a normal spin dash, execpt you only spin up once, and auto go when you hit the ground.
     
  12. Qjimbo

    Qjimbo

    Your friendly neighbourhood lemming. Oldbie
    Sorry for the necro bump, but I'm very curious how the code here compares to the implementation in the Sonic 3 Prototype. Any idea yet?

    Also, I was fairly certain that some sonic hacks had a drop-dash type move prior to Sonic Mania's release, but now I'm starting to wonder if I'm getting mixed up with Sonic Megamix's homing attack...
     
  13. Liliam

    Liliam

    Oldbie
    1,563
    117
    43
     
  14. Hez

    Hez

    Oldbie
    Feel free to poke a hole in this theory, but could this not be a very poor/halfassed attempt/poor removal of an abandoned peelout move? It seems awfully silly to have the up key initiate this.

    EDIT: I'm no advanced coder, but basically it ALMOST looks like someone wanted to keep the code for later, but didn't want it to be initiated easily. I'm not really sure, but I don't see it as being a functional or intended "drop dash". Since the other elemental shields seem to function as intended.
     
  15. MarkeyJester

    MarkeyJester

    Original, No substitute Resident Jester
    2,235
    491
    63
    Japan
    If you perform the move, but then while in the air, hold down before you land on the floor, you'll instantly go into a spindash charge without boosting. This is due to the spindash start flag being set, and the spindash timer being reset when you land on the floor.

    EDIT: Derp, this was mentioned in the quote, couldn't see it because it was collapsed d=

    So I agree this probably isn't the type of "drop dash" people think it is, I disagree it being a peelout due to the activation occurring when landing on a floor, that would make no sense.
     
    Last edited: Nov 19, 2019
  16. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,785
    365
    63
    SonLVL
    It really works nothing like the Drop Dash as it appears in Mania. There's no charge timer, no special sprites, the way you activate it is different, and it just sets up a Spin Dash instead of having specific code for setting speeds based on the terrain you land on.
     
    • Agree Agree x 4
    • Informative Informative x 3
    • List
  17. Qjimbo

    Qjimbo

    Your friendly neighbourhood lemming. Oldbie
    Thanks for the info, appreciate it.