Actions

SCHG How-to

Difference between revisions of "Collide with water after being hurt"

From Sonic Retro

Line 1: Line 1:
#REDIRECT [[Http://info.sonicretro.org/SCHG How-to:Collide with water after being hurt]]
+
{{GuideBy|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.
 +
 
 +
==Applying the change==
 +
===Sonic 2 SVN===
 +
First, locate '''Obj01_Hurt_Normal''', which should look like this:
 +
<asm>; 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
 +
</asm>
 +
Somewhere before the last line, add a branch to '''Sonic_Water''', like so:
 +
<asm> 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
 +
</asm>
 +
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:
 +
<asm>; 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
 +
</asm>
 +
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.
 +
 
 +
==Explaination==
 +
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.

Revision as of 11:57, 25 May 2011

(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.

Applying the change

Sonic 2 SVN

First, locate Obj01_Hurt_Normal, which should look like this: <asm>; 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 </asm> Somewhere before the last line, add a branch to Sonic_Water, like so: <asm> 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 </asm> 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: <asm>; 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

</asm> 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.

Explaination

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.