Collide with water after being hurt
From Sonic Retro
Revision as of 11:10, 25 August 2018 by Black Squirrel (talk | contribs) (Text replacement - "\[\[Category:SCHG How-tos.*" to "")
(Original guide by MoDule)
In the main series 16-bit Sonic games, Sonic behaves strangely when getting hurt and then falling into water. He will retain his above water gravity even under water until he lands.
This guide will show how to have Sonic interact with water even when falling after getting hurt.
Contents
Applying the change
First, locate Obj01_Hurt, which should look like this:
Sonic 1 Hivebrain
Obj01_Hurt:
jsr (SpeedToPos).l
addi.w #$30,$12(a0)
btst #6,$22(a0)
beq.s loc_1380C
subi.w #$20,$12(a0)
loc_1380C:
bsr.w Sonic_HurtStop
bsr.w Sonic_LevelBound
bsr.w Sonic_RecordPos
bsr.w Sonic_Animate
bsr.w LoadSonicDynPLC
jmp (DisplaySprite).l
Somewhere before the last line, add a branch to Sonic_Water, like so:
bsr.w Sonic_HurtStop
bsr.w Sonic_LevelBound
bsr.w Sonic_RecordPos
bsr.w Sonic_Water ; <--
bsr.w Sonic_Animate
bsr.w LoadSonicDynPLC
jmp (DisplaySprite).l
With this, Sonic should now behave as expected when falling into water, but still feels strange exiting it.He bounces awfully low, if he exits the water after getting hurt. To fix this, locate Obj01_OutWater add a line here
; loc_1A1FE:
Obj01_OutWater:
bclr #6,$22(a0)
beq.s locret_12D80
; ...
asl $12(a0)
tst.w $12(a0) ; <--
; ...
With this line added, Sonic will always get the speed boost when exiting water.
Sonic 2 SVN
First, locate Obj01_Hurt_Normal, which should look like this:
; loc_1B13A:
Obj01_Hurt_Normal:
tst.b routine_secondary(a0)
bmi.w Sonic_HurtInstantRecover
jsr (ObjectMove).l
addi.w #$30,y_vel(a0)
btst #6,status(a0)
beq.s +
subi.w #$20,y_vel(a0)
+
cmpi.w #-$100,(Camera_Min_Y_pos).w
bne.s +
andi.w #$7FF,y_pos(a0)
+
bsr.w Sonic_HurtStop
bsr.w Sonic_LevelBound
bsr.w Sonic_RecordPos
bsr.w Sonic_Animate
bsr.w LoadSonicDynPLC
jmp (DisplaySprite).l
Somewhere before the last line, add a branch to Sonic_Water, like so:
bsr.w Sonic_HurtStop
bsr.w Sonic_LevelBound
bsr.w Sonic_RecordPos
bsr.w Sonic_Water ; <--
bsr.w Sonic_Animate
bsr.w LoadSonicDynPLC
jmp (DisplaySprite).l
With this, Sonic should now behave as expected when falling into water, but still feels strange exiting it.He bounces awfully low, if he exits the water after getting hurt. To fix this, locate Obj01_OutWater and comment out a few line as shown here:
; loc_1A1FE:
Obj01_OutWater:
bclr #6,status(a0) ; unset underwater flag
beq.s return_1A18C ; if already above water, branch
[...]
; cmpi.b #4,routine(a0) ; <-- is Sonic falling back from getting hurt?
; beq.s + ; <-- if yes, branch
asl y_vel(a0)
;+ ; <--
tst.w y_vel(a0)
beq.w return_1A18C
move.w #$100,(Sonic_Dust+anim).w ; splash animation
movea.l a0,a1
bsr.w ResumeMusic
cmpi.w #-$1000,y_vel(a0)
bgt.s +
move.w #-$1000,y_vel(a0) ; limit upward y velocity exiting the water
+
move.w #SndID_Splash,d0 ; splash sound
jmp (PlaySound).l
; End of subroutine Sonic_Water
With these lines commented out, Sonic will always get the speed boost when exiting water.
Things to keep in mind
This change in behavior needs to be applied to every character object in the game, not just Sonic.
Explanation
The reason Sonic doesn't interact with water when getting hurt is because the water handling routine is only called when he is in his normal state. The code for his hurt state lacks a call to this routine. Adding a branch to the water handling routine makes him interact with water almost as one would expect. The lines that are commented out in the second part of the guide are code that checks if Sonic is in his Hurt state, something that was originally impossible, and skips the speed boost he would usually get from exiting the water. With the lower y-velocity he gets from being hurt under water, the missing boost and higher gravity above water explains why he falls back into the water almost immediately.
|Collide with water after being hurt]]