Actions

SCHG How-to

Difference between revisions of "Fix Scattered Rings Underwater Physics"

From Sonic Retro

m (Added temp and category)
(Added the Sonic 2 fix. Gonna add S3K... Then maybe add a contents table and headers.)
Line 4: Line 4:
  
 
This is something that occurs in all 3 Sonic the Hedgehog Mega Drive games (and by 3, that IS counting S3&K as one game, though S&K has no water anyway, so it wouldn't be included regardless... but I digress). But is it really a bug? or is it merely a design choice? In either case, it's something that could stand to be fixed, and this guide tells you how to fix the ring physics in all of the games. First off... let's start with the original...
 
This is something that occurs in all 3 Sonic the Hedgehog Mega Drive games (and by 3, that IS counting S3&K as one game, though S&K has no water anyway, so it wouldn't be included regardless... but I digress). But is it really a bug? or is it merely a design choice? In either case, it's something that could stand to be fixed, and this guide tells you how to fix the ring physics in all of the games. First off... let's start with the original...
 +
  
 
'''Sonic 1 fix''' - ''This guide uses the SVN disassembly.''
 
'''Sonic 1 fix''' - ''This guide uses the SVN disassembly.''
Line 115: Line 116:
 
This ensures when underwater, the gravity is not as great. Otherwise, the rings will gain speed and then it won't give the desired underwater effect.
 
This ensures when underwater, the gravity is not as great. Otherwise, the rings will gain speed and then it won't give the desired underwater effect.
  
 +
 +
'''Sonic 2 fix''' - ''This guide uses the Xenowhirl disassembly.''
 +
 +
First, go to "''loc_120BA:''" (part of the scattered rings object code) and find this bit of coding:
 +
<asm>
 +
  bsr.w JmpTo4_CalcSine
 +
  move.w d4,d2
 +
  lsr.w #8,d2
 +
</asm>
 +
 +
 +
Just underneath, paste this:
 +
 +
<asm>
 +
        tst.b  (Water_flag).w          ; Does the level have water?
 +
        beq.s  +                      ; If not, branch and skip underwater checks
 +
        move.w  (Water_Level_2).w,d6    ; Move water level to d6
 +
        cmp.w  y_pos(a0),d6            ; Is the ring object underneath the water level?
 +
        bgt.s  +                      ; If not, branch and skip underwater commands
 +
        asr.w  #$1,d0                  ; Half d0.  Makes the ring's x_vel bounce to the left/right slower
 +
        asr.w  #$1,d1                  ; Half d1.  Makes the ring's y_vel bounce up/down slower
 +
+
 +
</asm>
 +
 +
 +
 +
So, you should end up with something looking like this:
 +
 +
<asm>
 +
loc_120BA:
 +
        _move.b #$37,0(a1) ; load obj37
 +
        addq.b  #2,routine(a1)
 +
        move.b  #8,y_radius(a1)
 +
        move.b  #8,x_radius(a1)
 +
        move.w  x_pos(a0),x_pos(a1)
 +
        move.w  y_pos(a0),y_pos(a1)
 +
        move.l  #Obj25_MapUnc_12382,mappings(a1)
 +
        move.w  #$26BC,art_tile(a1)
 +
        bsr.w  Adjust2PArtPointer2
 +
        move.b  #$84,render_flags(a1)
 +
        move.b  #3,priority(a1)
 +
        move.b  #$47,collision_flags(a1)
 +
        move.b  #8,width_pixels(a1)
 +
        move.b  #-1,(Ring_spill_anim_counter).w
 +
        tst.w  d4
 +
        bmi.s  loc_12132
 +
        move.w  d4,d0
 +
        bsr.w  JmpTo4_CalcSine
 +
        move.w  d4,d2
 +
        lsr.w  #8,d2
 +
        tst.b  (Water_flag).w          ; Does the level have water?
 +
        beq.s  +                      ; If not, branch and skip underwater checks
 +
        move.w  (Water_Level_2).w,d6    ; Move water level to d6
 +
        cmp.w  y_pos(a0),d6            ; Is the ring object underneath the water level?
 +
        bgt.s  +                      ; If not, branch and skip underwater commands
 +
        asr.w  #$1,d0                  ; Half d0.  Makes the ring's x_vel bounce to the left/right slower
 +
        asr.w  #$1,d1                  ; Half d1.  Makes the ring's y_vel bounce up/down slower
 +
+
 +
        asl.w  d2,d0
 +
        asl.w  d2,d1
 +
        move.w  d0,d2
 +
        move.w  d1,d3
 +
        addi.b  #$10,d4
 +
        bcc.s  loc_12132
 +
        subi.w  #$80,d4
 +
        bcc.s  loc_12132
 +
        move.w  #$288,d4
 +
</asm>
 +
 +
This ensures that when underwater, the rings x_vel and y_vel are halved so they appear to be moving slower.
 +
 +
 +
Next, go to label "Obj_37_sub_2:" and under
 +
 +
<asm>
 +
        move.b  (Ring_spill_anim_frame).w,mapping_frame(a0)
 +
        bsr.w  ObjectMove
 +
        addi.w  #$18,y_vel(a0)
 +
</asm>
 +
 +
 +
Put this:
 +
<asm>
 +
        tst.b  (Water_flag).w          ; Does the level have water?
 +
        beq.s  +                      ; If not, branch and skip underwater checks
 +
        move.w  (Water_Level_2).w,d6    ; Move water level to d6
 +
        cmp.w  y_pos(a0),d6            ; Is the ring object underneath the water level?
 +
        bgt.s  +                      ; If not, branch and skip underwater commands
 +
        subi.w  #$E,y_vel(a0)          ; Reduce gravity by $E ($18-$E=$A), giving the underwater effect for the rings
 +
+
 +
</asm>
 +
 +
You can change the value of the gravity if you like, but I found $E to suit.
 +
Anyway, you should have something looking like this:
 +
 +
<asm>
 +
Obj_37_sub_2:
 +
        move.b  (Ring_spill_anim_frame).w,mapping_frame(a0)
 +
        bsr.w  ObjectMove
 +
        addi.w  #$18,y_vel(a0)
 +
        tst.b  (Water_flag).w          ; Does the level have water?
 +
        beq.s  +                      ; If not, branch and skip underwater checks
 +
        move.w  (Water_Level_2).w,d6    ; Move water level to d6
 +
        cmp.w  y_pos(a0),d6            ; Is the ring object underneath the water level?
 +
        bgt.s  +                      ; If not, branch and skip underwater commands
 +
        subi.w  #$E,y_vel(a0)          ; Reduce gravity by $E ($18-$E=$A), giving the underwater effect for the rings
 +
+
 +
        bmi.s  loc_121B8
 +
        move.b  ($FFFFFE0F).w,d0
 +
        add.b  d7,d0
 +
        andi.b  #7,d0
 +
        bne.s  loc_121B8
 +
        tst.b  render_flags(a0)
 +
        bpl.s  loc_121D0
 +
        jsr    (RingCheckFloorDist).l
 +
        tst.w  d1
 +
        bpl.s  loc_121B8
 +
        add.w  d1,y_pos(a0)
 +
        move.w  y_vel(a0),d0
 +
        asr.w  #2,d0
 +
        sub.w  d0,y_vel(a0)
 +
        neg.w  y_vel(a0)
 +
</asm>
 +
 +
This ensures when underwater, the gravity is not as great. Otherwise, the rings will gain speed and then it won't give the desired underwater effect.
 +
 +
{{S1Howtos}}
 
{{S2Howtos}}
 
{{S2Howtos}}
 
[[Category:SCHG How-tos|Fix Scattered Rings Underwater Physics]]
 
[[Category:SCHG How-tos|Fix Scattered Rings Underwater Physics]]

Revision as of 09:50, 23 April 2012

(Guide for all 3 games written by redhotsonic.

Quote from redhotsonic, - "Ah, the scattered rings when you get hurt. It can cause slowdown to your game, and even mess up the underwater palette. Now, when Sonic is underwater, his movement and his gravity is changed so he moves slower to act like he's in water. But when he is hurt under water, isn't it funny that the scattered rings still act the same as if you weren't in water?"

This is something that occurs in all 3 Sonic the Hedgehog Mega Drive games (and by 3, that IS counting S3&K as one game, though S&K has no water anyway, so it wouldn't be included regardless... but I digress). But is it really a bug? or is it merely a design choice? In either case, it's something that could stand to be fixed, and this guide tells you how to fix the ring physics in all of the games. First off... let's start with the original...


Sonic 1 fix - This guide uses the SVN disassembly.

First, In your disassembly, go to "_incObj\25 & 37 Rings.asm" Go to @makerings: (part of the scattered rings object code) and find this bit of coding: <asm>

    bsr.w   CalcSine
    move.w  d4,d2
    lsr.w   #8,d2

</asm>

Just underneath, paste this: <asm>

               tst.b   ($FFFFF64C).w           ; Does the level have water?
               beq.s   @skiphalvingvel         ; If not, branch and skip underwater checks
               move.w  ($FFFFF646).w,d6        ; Move water level to d6
               cmp.w   y_pos(a0),d6            ; Is the ring object underneath the water level?
               bgt.s   @skiphalvingvel         ; If not, branch and skip underwater commands
               asr.w   #$1,d0                  ; Half d0.  Makes the ring's x_vel bounce to the left/right slower
               asr.w   #$1,d1                  ; Half d1.  Makes the ring's y_vel bounce up/down slower

@skiphalvingvel: </asm>

'You should end up with something looking like this:' <asm> @makerings:

               move.b  #id_RingLoss,0(a1) ; load bouncing ring object
               addq.b  #2,obRoutine(a1)
               move.b  #8,obHeight(a1)
               move.b  #8,obWidth(a1)
               move.w  obX(a0),obX(a1)
               move.w  obY(a0),obY(a1)
               move.l  #Map_Ring,obMap(a1)
               move.w  #$27B2,obGfx(a1)
               move.b  #4,obRender(a1)
               move.b  #3,obPriority(a1)
               move.b  #$47,obColType(a1)
               move.b  #8,obActWid(a1)
               move.b  #-1,(v_ani3_time).w
               tst.w   d4
               bmi.s   @loc_9D62
               move.w  d4,d0
               bsr.w   CalcSine
               move.w  d4,d2
               lsr.w   #8,d2
               tst.b   ($FFFFF64C).w           ; Does the level have water?
               beq.s   @skiphalvingvel         ; If not, branch and skip underwater checks
               move.w  ($FFFFF646).w,d6        ; Move water level to d6
               cmp.w   y_pos(a0),d6            ; Is the ring object underneath the water level?
               bgt.s   @skiphalvingvel         ; If not, branch and skip underwater commands
               asr.w   #$1,d0                  ; Half d0.  Makes the ring's x_vel bounce to the left/right slower
               asr.w   #$1,d1                  ; Half d1.  Makes the ring's y_vel bounce up/down slower

@skiphalvingvel:

               asl.w   d2,d0
               asl.w   d2,d1
               move.w  d0,d2
               move.w  d1,d3
               addi.b  #$10,d4
               bcc.s   @loc_9D62
               subi.w  #$80,d4
               bcc.s   @loc_9D62
               move.w  #$288,d4

</asm> This ensures that when underwater, the rings x_vel and y_vel are halved so they appear to be moving slower.

Next, go to label "RLoss_Bounce:" and under <asm>

               move.b  (v_ani3_frame).w,obFrame(a0)
               bsr.w   SpeedToPos
               addi.w  #$18,obVelY(a0)

</asm> place this: <asm>

               tst.b   ($FFFFF64C).w           ; Does the level have water?
               beq.s   @skipbounceslow         ; If not, branch and skip underwater checks
               move.w  ($FFFFF646).w,d6        ; Move water level to d6
               cmp.w   y_pos(a0),d6            ; Is the ring object underneath the water level?
               bgt.s   @skipbounceslow         ; If not, branch and skip underwater commands
               subi.w  #$E,obVelY(a0)          ; Reduce gravity by $E ($18-$E=$A), giving the underwater effect

@skipbounceslow: </asm> You can change the value of the gravity if you like, but I found $E to suit. Anyway, you should have something looking like this: <asm> RLoss_Bounce:  ; Routine 2

               move.b  (v_ani3_frame).w,obFrame(a0)
               bsr.w   SpeedToPos
               addi.w  #$18,obVelY(a0)
               tst.b   ($FFFFF64C).w           ; Does the level have water?
               beq.s   @skipbounceslow         ; If not, branch and skip underwater checks
               move.w  ($FFFFF646).w,d6        ; Move water level to d6
               cmp.w   y_pos(a0),d6            ; Is the ring object underneath the water level?
               bgt.s   @skipbounceslow         ; If not, branch and skip underwater commands
               subi.w  #$E,obVelY(a0)          ; Reduce gravity by $E ($18-$E=$A), giving the underwater effect

@skipbounceslow:

               bmi.s   @chkdel
               move.b  (v_vbla_byte).w,d0
               add.b   d7,d0
               andi.b  #3,d0
               bne.s   @chkdel
               jsr     ObjFloorDist
               tst.w   d1
               bpl.s   @chkdel
               add.w   d1,obY(a0)
               move.w  obVelY(a0),d0
               asr.w   #2,d0
               sub.w   d0,obVelY(a0)
               neg.w   obVelY(a0)

</asm> This ensures when underwater, the gravity is not as great. Otherwise, the rings will gain speed and then it won't give the desired underwater effect.


Sonic 2 fix - This guide uses the Xenowhirl disassembly.

First, go to "loc_120BA:" (part of the scattered rings object code) and find this bit of coding: <asm>

 bsr.w JmpTo4_CalcSine
 move.w d4,d2
 lsr.w #8,d2

</asm>


Just underneath, paste this:

<asm>

       tst.b   (Water_flag).w          ; Does the level have water?
       beq.s   +                       ; If not, branch and skip underwater checks
       move.w  (Water_Level_2).w,d6    ; Move water level to d6
       cmp.w   y_pos(a0),d6            ; Is the ring object underneath the water level?
       bgt.s   +                       ; If not, branch and skip underwater commands
       asr.w   #$1,d0                  ; Half d0.  Makes the ring's x_vel bounce to the left/right slower
       asr.w   #$1,d1                  ; Half d1.  Makes the ring's y_vel bounce up/down slower

+ </asm>


So, you should end up with something looking like this:

<asm> loc_120BA:

       _move.b #$37,0(a1) ; load obj37
       addq.b  #2,routine(a1)
       move.b  #8,y_radius(a1)
       move.b  #8,x_radius(a1)
       move.w  x_pos(a0),x_pos(a1)
       move.w  y_pos(a0),y_pos(a1)
       move.l  #Obj25_MapUnc_12382,mappings(a1)
       move.w  #$26BC,art_tile(a1)
       bsr.w   Adjust2PArtPointer2
       move.b  #$84,render_flags(a1)
       move.b  #3,priority(a1)
       move.b  #$47,collision_flags(a1)
       move.b  #8,width_pixels(a1)
       move.b  #-1,(Ring_spill_anim_counter).w
       tst.w   d4
       bmi.s   loc_12132
       move.w  d4,d0
       bsr.w   JmpTo4_CalcSine
       move.w  d4,d2
       lsr.w   #8,d2
       tst.b   (Water_flag).w          ; Does the level have water?
       beq.s   +                       ; If not, branch and skip underwater checks
       move.w  (Water_Level_2).w,d6    ; Move water level to d6
       cmp.w   y_pos(a0),d6            ; Is the ring object underneath the water level?
       bgt.s   +                       ; If not, branch and skip underwater commands
       asr.w   #$1,d0                  ; Half d0.  Makes the ring's x_vel bounce to the left/right slower
       asr.w   #$1,d1                  ; Half d1.  Makes the ring's y_vel bounce up/down slower

+

       asl.w   d2,d0
       asl.w   d2,d1
       move.w  d0,d2
       move.w  d1,d3
       addi.b  #$10,d4
       bcc.s   loc_12132
       subi.w  #$80,d4
       bcc.s   loc_12132
       move.w  #$288,d4

</asm>

This ensures that when underwater, the rings x_vel and y_vel are halved so they appear to be moving slower.


Next, go to label "Obj_37_sub_2:" and under

<asm>

       move.b  (Ring_spill_anim_frame).w,mapping_frame(a0)
       bsr.w   ObjectMove
       addi.w  #$18,y_vel(a0)

</asm>


Put this: <asm>

       tst.b   (Water_flag).w          ; Does the level have water?
       beq.s   +                       ; If not, branch and skip underwater checks
       move.w  (Water_Level_2).w,d6    ; Move water level to d6
       cmp.w   y_pos(a0),d6            ; Is the ring object underneath the water level?
       bgt.s   +                       ; If not, branch and skip underwater commands
       subi.w  #$E,y_vel(a0)           ; Reduce gravity by $E ($18-$E=$A), giving the underwater effect for the rings

+ </asm>

You can change the value of the gravity if you like, but I found $E to suit. Anyway, you should have something looking like this:

<asm> Obj_37_sub_2:

       move.b  (Ring_spill_anim_frame).w,mapping_frame(a0)
       bsr.w   ObjectMove
       addi.w  #$18,y_vel(a0)
       tst.b   (Water_flag).w          ; Does the level have water?
       beq.s   +                       ; If not, branch and skip underwater checks
       move.w  (Water_Level_2).w,d6    ; Move water level to d6
       cmp.w   y_pos(a0),d6            ; Is the ring object underneath the water level?
       bgt.s   +                       ; If not, branch and skip underwater commands
       subi.w  #$E,y_vel(a0)           ; Reduce gravity by $E ($18-$E=$A), giving the underwater effect for the rings

+

       bmi.s   loc_121B8
       move.b  ($FFFFFE0F).w,d0
       add.b   d7,d0
       andi.b  #7,d0
       bne.s   loc_121B8
       tst.b   render_flags(a0)
       bpl.s   loc_121D0
       jsr     (RingCheckFloorDist).l
       tst.w   d1
       bpl.s   loc_121B8
       add.w   d1,y_pos(a0)
       move.w  y_vel(a0),d0
       asr.w   #2,d0
       sub.w   d0,y_vel(a0)
       neg.w   y_vel(a0)

</asm>

This ensures when underwater, the gravity is not as great. Otherwise, the rings will gain speed and then it won't give the desired underwater effect.

SCHG How-To Guide: Sonic the Hedgehog (16-bit)
Fixing Bugs
Fix Demo Playback | Fix a Race Condition with Pattern Load Cues | Fix the SEGA Sound | Display the Press Start Button Text | Fix the Level Select Menu | Fix the Hidden Points Bug | Fix Accidental Deletion of Scattered Rings | Fix Ring Timers | Fix the Walk-Jump Bug | Correct Drowning Bugs | Fix the Death Boundary Bug | Fix the Camera Follow Bug | Fix Song Restoration Bugs | Fix the HUD Blinking | Fix the Level Select Graphics Bug | Fix a remember sprite related bug
Changing Design Choices
Change Spike Behavior | Collide with Water After Being Hurt | Fix Special Stage Jumping Physics | Improve the Fade In\Fade Out Progression Routines | Fix Scattered Rings' Underwater Physics | Remove the Speed Cap | Port the REV01 Background Effects | Port Sonic 2's Level Art Loader | Retain Rings Between Acts | Add Sonic 2 (Simon Wai Prototype) Level Select | Improve ObjectMove Subroutines | Port Sonic 2 Level Select
Adding Features
Add Spin Dash ( Part 1 / Part 2 / Part 3 / Part 4 ) | Add Eggman Monitor | Add Super Sonic | Add the Air Roll
Sound Features
Expand the Sound Index | Play Different Songs Per Act | Port Sonic 2 Final Sound Driver | Port Sonic 3's Sound Driver | Port Flamewing's Sonic 3 & Knuckles Sound Driver | Change The SEGA Sound
Extending the Game
Load Chunks From ROM | Add Extra Characters | Make an Alternative Title Screen | Use Dynamic Tilesets | Make GHZ Load Alternate Art | Make Ending Load Alternate Art | Add a New Zone | Set Up the Goggle Monitor | Add New Moves | Add a Dynamic Collision System | Dynamic Special Stage Walls System | Extend Sprite Mappings and Art Limit | Enigma Credits | Use Dynamic Palettes
Miscellaneous
Convert the Hivebrain 2005 Disassembly to ASM68K
Split Disassembly Guides
Set Up a Split Disassembly | Basic Level Editing | Basic Art Editing | Basic ASM Editing (Spin Dash)
SCHG How-To Guide: Sonic the Hedgehog 2 (16-bit)
Fixing Bugs
Fix Demo Playback | Fix a Race Condition with Pattern Load Cues | Fix Super Sonic Bugs | Use Correct Height When Roll Jumping | Fix Jump Height Bug When Exiting Water | Fix Screen Boundary Spin Dash Bug | Correct Drowning Bugs | Fix Camera Y Position for Tails | Fix Tails Subanimation Error | Fix Tails' Respawn Speeds | Fix Accidental Deletion of Scattered Rings | Fix Ring Timers | Fix Rexon Crash | Fix Monitor Collision Bug | Fix EHZ Deformation Bug | Correct CPZ Boss Attack Behavior | Fix Bug in ARZ Boss Arrow's Platform Behavior | Fix ARZ Boss Walking on Air Glitch | Fix ARZ Boss Sprite Behavior | Fix Multiple CNZ Boss Bugs | Fix HTZ Background Scrolling Mountains | Fix OOZ Launcher Speed Up Glitch | Fix DEZ Giant Mech Collision Glitch | Fix Boss Deconstruction Behavior | Fix Speed Bugs | Fix 14 Continues Cheat | Fix Debug Mode Crash | Fix 99+ Lives | Fix Sonic 2's Sega Screen
Design Choices
Remove the Air Speed Cap | Disable Floor Collision While Dying | Modify Super Sonic Transformation Methods & Behavior | Enable/Disable Tails in Certain Levels | Collide with Water After Being Hurt | Retain Rings When Returning at a Star Post | Improve the Fade In\Fade Out Progression Routines | Fix Scattered Rings' Underwater Physics | Insert LZ Water Ripple Effect | Restore Lost CPZ Boss Feature | Prevent SCZ Tornado Spin Dash Death | Improve ObjectMove Subroutines | Port S3K Rings Manager | Port S3K Object Manager | Port S3K Priority Manager | Edit Level Order with ASM‎ | Alter Ring Requirements in Special Stages | Make Special Stage Characters Use Normal DPLCs | Speed Up Ring Loss Process | Change spike behaviour in Sonic 2
Adding Features
Create Insta-kill and High Jump Monitors | Create Clone and Special Stage Monitors | Port Knuckles
Sound Features
Expand Music Index to Start at $00 | Port Sonic 1 Sound Driver | Port Sonic 2 Clone Driver | Port Sonic 3 Sound Driver | Port Flamewing's Sonic 3 & Knuckles Sound Driver | Expand the Music Index to Start at $00 (Sonic 2 Clone Driver Version) | Play Different Songs Per Act
Extending the Game
Extend the Level Index Past $10 | Extend the Level Select | Extend Water Tables | Add Extra Characters | Free Up 2 Universal SSTs