don't click here

Sonic Physics Guide

Discussion in 'Fangaming Discussion' started by Lapper, Apr 1, 2021.

  1. Crasher

    Crasher

    Why hello there! Member
    493
    52
    28
    From memory, you'll want to not use Unity's built-in physics. I implemented the physics in Unreal Engine 4, and the biggest issue I had for a while is that you couldn't change the direction of gravity for a single object - something that, iirc, Unity doesn't let you do at run-time on a per-object basis either.

    I could be completely wrong, but it's something worth looking into imo.
     
  2. Candescence

    Candescence

    Member
    1,994
    7
    18
    Sydney, Australia
    3D Indie Stuff
    I've actually been avoiding using Unity physics where possible aside from raycasting purely to replace the sensors, not even a rigidbody. Just tile colliders and raycasting.

    It is a bit surprising that there isn't a proper 2D implementation of Sonic physics for Unity and/or UE4 out there. Dash Engine for UE4 supposedly has one, but I cannot for the life of me get Dash Engine's arcane build process to work properly, so I can't test it.
     
  3. RetroKoH

    RetroKoH

    Member
    1,661
    17
    18
    Project Sonic 8x16
    Sweet merciful jesus, yes... I wish you were around to do this back when I first started working on my own engine in 2010. I'm combing through it now, and it is a massive improvement.

    Maybe now some of these Sonic Worlds engines can actually get their goddamn physics right instead of feeling janky and floaty.
     
    • Like Like x 2
    • Agree Agree x 1
    • List
  4. Techokami

    Techokami

    For use only on NTSC Genesis systems Researcher
    1,361
    59
    28
    HoleNet!
    Sonic Worlds Next
    This is why I'm having the engine being completely rewritten from scratch using this guide as a basis. :O
     
  5. Pink-bot

    Pink-bot

    Member
    9
    1
    1
    Awesome guide but Ive still got a ton of questions (mostly how different badniks work in the games but also some more slope stuff). How would I go about getting the missing info myself? I noticed you mentioned recording, what software do you recommend?
     
  6. Lapper

    Lapper

    Member
    1,680
    536
    93
    England
    Sonic Studio, Sonic Physics Guide, Kyle & Lucy: WW, Freedom Planet 2
    I mostly look heavily into the Disassembles (ASM code) to understand and reconstruct systems, learn the logic and get any precise values. Steep learning curve though. You can sometimes record the game and count frames or motion for things like some animation speeds (but not variable ones like Sonic's walk/run) or movement speeds of things that don't vary (like not gravity, but you can measure projectiles that travel straight or motobug's horizontal movement etc). Typically though, reading the ASM disassembly code is the way to go.

    However, I & Mercury have also done some of the work for you with the Sonic 1 Overlay
    https://info.sonicretro.org/SPG:Overlay_Scripts

    It can show you all of Sonic's variables, and also all object's solidity, hitboxes, and terrain sensors. Should help you with small nuggets of info with how certain things work in S1. Updates to it are coming so be sure to check back here, I will post about it. Also working on the same for 2 and 3k.

    Shows you all the solid slope tiles too! Though all info you need about how slopes work should be on the guide.

    ------------------------------------

    Some recent Physics guide updates:
    - Game Enemies now have their own page! (https://info.sonicretro.org/SPG:Game_Enemies) The goal will be to fill this page with explanations of both Badniks and Bosses of each game. The existing Game Objects page will expand and focus on general gimmicks.
    - Some information has been lifted from the "Solid Tiles" page to it's own "Slope Collision" page (https://info.sonicretro.org/SPG:Slope_Collision), allowing for easier navigation and more focused explanations on each.
    - Research is being done for the mechanics, collision and physics of the Sonic 1 Special Stage:
    https://twitter.com/LapperDev/status/1495565387093745665

    Essentially been doing some code experimenting recreating the Special Stage physics while researching the code. Did the same with Solid objects a while back. The video is a heavy wip of course - it generally functions, was just a couple hours investigation. Once all the features can be replicated and understood it will end up written up on the guide.
     
    Last edited: Feb 21, 2022
    • Like Like x 3
    • Informative Informative x 3
    • List
  7. Lapper

    Lapper

    Member
    1,680
    536
    93
    England
    Sonic Studio, Sonic Physics Guide, Kyle & Lucy: WW, Freedom Planet 2
    Update of the recreation of special stage physics research
    (First half is the recreation and original overlaid ontop eachother, and second half is a comparison).
    Thanks to Mercury for helping & figuring out some of the more complex details. Very close to being fully explainable.
     
    Last edited: Mar 13, 2022
  8. Devon

    Devon

    There's nothing left but faith Tech Member
    771
    453
    63
    A quick question. In the camera page, it says this:
    Looking at the original assembly code, the scroll cap is 6 px/frame if the ground speed is less than 8, otherwise, it's 16 px/frame. Where'd the "if the Player's Y speed is less than or equal to 6" part come from?

    For example, in the Sonic 2 disassembly:
    Code (Text):
    1.     mvabs.w    inertia(a0),d1    ; get player ground velocity, force it to be positive
    2.     cmpi.w    #$800,d1    ; is the player travelling very fast?
    3.     bhs.s    .doScroll_fast    ; if he is, branch
    4. ;.doScroll_medium:
    5.     move.w    #6<<8,d1    ; If player is going too fast, cap camera movement to 6 pixels per frame
    6.     cmpi.w    #6,d0        ; is player going down too fast?
    7.     bgt.s    .scrollDown_max    ; if so, move camera at capped speed
    8.     cmpi.w    #-6,d0        ; is player going up too fast?
    9.     blt.s    .scrollUp_max    ; if so, move camera at capped speed
    10.     bra.s    .scrollUpOrDown    ; otherwise, move camera at player's speed
    11.  
    12.     ....
    13.  
    14. ; ===========================================================================
    15. ; loc_D7FC:
    16. .doScroll_fast:
    17.     ; related code appears in ScrollBG
    18.     ; S3K uses 24 instead of 16
    19.     move.w    #16<<8,d1    ; If player is going too fast, cap camera movement to $10 pixels per frame
    20.     cmpi.w    #16,d0        ; is player going down too fast?
    21.     bgt.s    .scrollDown_max    ; if so, move camera at capped speed
    22.     cmpi.w    #-16,d0        ; is player going up too fast?
    23.     blt.s    .scrollUp_max    ; if so, move camera at capped speed
    24.     bra.s    .scrollUpOrDown    ; otherwise, move camera at player's speed

    The fast vertical scroll cap is 24 px/frame, in S3K, too (the level renderer in S3K can draw up to 2 rows/columns of blocks at once).

    I'd make a wiki edit, but I also didn't want to tread over your work at the same time.
     
  9. Lapper

    Lapper

    Member
    1,680
    536
    93
    England
    Sonic Studio, Sonic Physics Guide, Kyle & Lucy: WW, Freedom Planet 2
    Ah, so looking back through the edits those used to both mention "Y Speed" and "6", seems a correction was made to the info in one set of brackets and neglected to correct the other.

    If you want to make a correction based on knowledge of the assembly code, you can definitely go for it of course.
     
  10. Devon

    Devon

    There's nothing left but faith Tech Member
    771
    453
    63
    A'ight. I also went ahead and redid a few explanations to be more accurate to how the Assembly code works, and also how it functions between the different games. Particularly wanted to explain the "focal point" (or "bias") variable(s).
     
    Last edited: Jul 2, 2022
    • Informative Informative x 1
    • List
  11. Lapper

    Lapper

    Member
    1,680
    536
    93
    England
    Sonic Studio, Sonic Physics Guide, Kyle & Lucy: WW, Freedom Planet 2
    • Useful Useful x 2
    • Informative Informative x 1
    • List
  12. foobles

    foobles

    Member
    8
    6
    3
    I found a slight inaccuracy/piece of incomplete info in the section on jumping:
    Through testing with the overlay mod (thank you for developing that, too :thumbsup:), I found that the exact same thing occurs in Sonic 1 as well. Correspondingly, the issue of 1 frame where Sonic is 5 pixels too high after landing happens there as well.
     
    • Informative Informative x 1
    • List
  13. Devon

    Devon

    There's nothing left but faith Tech Member
    771
    453
    63
    Also happens in Sonic 3K as well. What's going on is that it checks if Sonic is rolling after resetting to the default hitbox size, and if he's rolling it goes to another piece of code that sets a flag, but doesn't shrink Sonic's hitbox down.

    Interestingly, it doesn't happen in Sonic CD. Sonic CD doesn't reset the hitbox size to default before checking if Sonic was rolling before jumping like the mainline games do.
     
    • Informative Informative x 1
    • List
  14. Brainulator

    Brainulator

    Regular garden-variety member Member
    I assume that has to do with the fact that Sonic CD is the only one among the main Genesis games to not prevent you from changing direction after jumping from a roll?
     
  15. Devon

    Devon

    There's nothing left but faith Tech Member
    771
    453
    63
    Actually, it still sets the roll flag and skips over the code that sets the shrunken hitbox size, it just doesn't check it in the horizontal movement function when in the air. The actual change in this case is that they removed the code that resets the hitbox size to the default size before shrinking it, so if you were rolling before, it should remain shrunken.
     
    • Informative Informative x 2
    • List
  16. Lapper

    Lapper

    Member
    1,680
    536
    93
    England
    Sonic Studio, Sonic Physics Guide, Kyle & Lucy: WW, Freedom Planet 2
    Oh right, thanks for pointing this out. I knew this already so I'm not sure why it's written that way. Probably because landing from a roll jump in S1 feels fine when playing, but you can notice it easily in S2.