Difference between revisions of "Use correct height when roll jumping"
From Sonic Retro
m (moved User:MoDule/Use correct height when roll jumping to SCHG How-to:Use correct height when roll jumping: Guide is ready to be posted) |
m (Text replacement - "\[\[Category:SCHG How-tos.*" to "") |
||
(6 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{GuideBy|MoDule}} | {{GuideBy|MoDule}} | ||
+ | (S3K fix by ThomasSpeedrunner) | ||
In every main series 16-bit Sonic game, there is a small bug in Sonic's jumping code that assigns him the wrong height and width when jumping while rolling on the ground. Most of the time this goes unnoticed, however occasionally when landing it will cause Sonic to be moved up too far, back into the air and make him temporarily unable to jump. This guide will show how to fix the bug and explain its origin. | In every main series 16-bit Sonic game, there is a small bug in Sonic's jumping code that assigns him the wrong height and width when jumping while rolling on the ground. Most of the time this goes unnoticed, however occasionally when landing it will cause Sonic to be moved up too far, back into the air and make him temporarily unable to jump. This guide will show how to fix the bug and explain its origin. | ||
Line 6: | Line 7: | ||
===Sonic 2, SVN disassembly=== | ===Sonic 2, SVN disassembly=== | ||
Locate the ''Sonic_Jump'' routine and comment out two lines as follows: | Locate the ''Sonic_Jump'' routine and comment out two lines as follows: | ||
− | <asm>; loc_1AA38: | + | <syntaxhighlight lang="asm">; loc_1AA38: |
Sonic_Jump: | Sonic_Jump: | ||
move.b (Ctrl_1_Press_Logical).w,d0 | move.b (Ctrl_1_Press_Logical).w,d0 | ||
Line 32: | Line 33: | ||
rts | rts | ||
; End of function Sonic_Jump | ; End of function Sonic_Jump | ||
− | </asm> | + | </syntaxhighlight> |
+ | |||
+ | ===Sonic 3 & Knuckles, SVN disassembly=== | ||
+ | The routine to find here: ''Sonic_Jump:''. For those who prefer using location-based labels, this is ''sub_117DA:''. Scroll down until you see this or something like it (this has SSTs labeled to enhance readability): | ||
+ | <syntaxhighlight lang="asm"> move.b default_y_radius(a0),y_radius(a0) ; <-- This line | ||
+ | move.b default_x_radius(a0),x_radius(a0) ; <-- This line | ||
+ | btst #2,status(a0) | ||
+ | bne.s loc_118B4 | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Comment out or delete the indicated lines. | ||
==Things to keep in mind== | ==Things to keep in mind== | ||
− | This bug will be present in any other player objects as well, | + | This bug will be present in any other player objects as well, meaning it needs to be fixed for Tails and Knuckles if they exist, as well as any other characters you may have. Another small thing to note is that this reduces Sonic's hitbox when roll jumping. This shouldn't be much of a problem, though. |
==The bug explained== | ==The bug explained== | ||
The normal procedure for when Sonic jumps is to change him into a ball, reduce his size and due to the height difference move him down a bit, as seen here: | The normal procedure for when Sonic jumps is to change him into a ball, reduce his size and due to the height difference move him down a bit, as seen here: | ||
− | <asm> move.b #$E,y_radius(a0) ; set to rolling height | + | <syntaxhighlight lang="asm"> move.b #$E,y_radius(a0) ; set to rolling height |
move.b #7,x_radius(a0) ; and width | move.b #7,x_radius(a0) ; and width | ||
move.b #2,anim(a0) ; use "jumping" animation | move.b #2,anim(a0) ; use "jumping" animation | ||
bset #2,status(a0) | bset #2,status(a0) | ||
addq.w #5,y_pos(a0) ;<-- move to ground | addq.w #5,y_pos(a0) ;<-- move to ground | ||
− | </asm> | + | </syntaxhighlight> |
+ | |||
+ | S3K hackers, yours will look something like this: | ||
+ | <syntaxhighlight lang="asm"> move.b #$E,y_radius(a0) ; set to rolling height | ||
+ | move.b #7,x_radius(a0) ; set to rolling width | ||
+ | move.b #id_SonicRoll,anim(a0) ; use "jumping" animation | ||
+ | bset #2,status(a0) | ||
+ | move.b y_radius(a0),d0 | ||
+ | sub.b default_y_radius(a0),d0 | ||
+ | ext.w d0 | ||
+ | tst.b (Reverse_gravity_flag).w | ||
+ | beq.s loc_118AE | ||
+ | neg.w d0 | ||
+ | |||
+ | loc_118AE: | ||
+ | sub.w d0,y_pos(a0) ; <-- move to ground | ||
+ | </syntaxhighlight> | ||
+ | |||
The problem lies with the four lines above this code: | The problem lies with the four lines above this code: | ||
− | <asm> move.b #$13,y_radius(a0) ; set to standing height | + | <syntaxhighlight lang="asm"> move.b #$13,y_radius(a0) ; set to standing height |
move.b #9,x_radius(a0) ; and width | move.b #9,x_radius(a0) ; and width | ||
btst #2,status(a0) ; is Sonic rolling? | btst #2,status(a0) ; is Sonic rolling? | ||
bne.s Sonic_RollJump ; if yes, branch | bne.s Sonic_RollJump ; if yes, branch | ||
− | </asm> | + | </syntaxhighlight> |
− | The last two lines make sense. If Sonic is already rolling his size and position should be correct, so the code underneath can be skipped. The other two lines would appear to reset Sonic to his normal size, something that doesn't make sense in this context. When jumping normally these two lines have no effect whatsoever, as they are undone shortly afterward. Unfortunately, the code that fixes this problem is skipped when Sonic is already rolling and he ends up with the wrong height. Now when he lands on the ground this | + | |
− | <asm>; loc_1B0AC: | + | S3K hackers, yours will look something like this: |
+ | <syntaxhighlight lang="asm"> move.b default_y_radius(a0),y_radius(a0) | ||
+ | move.b default_x_radius(a0),x_radius(a0) | ||
+ | btst #2,status(a0) | ||
+ | bne.s loc_118B4 | ||
+ | </syntaxhighlight> | ||
+ | The last two lines make sense. If Sonic is already rolling his size and position should be correct, so the code underneath can be skipped. The other two lines would appear to reset Sonic to his normal size, something that doesn't make sense in this context. When jumping normally these two lines have no effect whatsoever, as they are undone shortly afterward. Unfortunately, the code that fixes this problem is skipped when Sonic is already rolling, and he ends up with the wrong height. Now, when he lands on the ground, this code runs: | ||
+ | <syntaxhighlight lang="asm">; loc_1B0AC: | ||
Sonic_ResetOnFloor_Part2: | Sonic_ResetOnFloor_Part2: | ||
[...] | [...] | ||
Line 63: | Line 98: | ||
move.b #AniIDSonAni_Walk,anim(a0) ; use running/walking/standing animation | move.b #AniIDSonAni_Walk,anim(a0) ; use running/walking/standing animation | ||
subq.w #5,y_pos(a0) ;<-- move Sonic up 5 pixels so the increased height doesn't push him into the ground | subq.w #5,y_pos(a0) ;<-- move Sonic up 5 pixels so the increased height doesn't push him into the ground | ||
− | </ | + | </syntaxhighlight> |
− | What this code does, is reset Sonic to his normal standing height and move him up by 5 pixels when he is in a spinning state. This all makes sense under the assumption that Sonic is actually using his rolling height. If he isn't, he'll end up 5 pixels in the air, which is exactly what happens | + | What this code does, is reset Sonic to his normal standing height and move him up by 5 pixels when he is in a spinning state. This all makes sense, under the assumption that Sonic is ''actually'' using his rolling height. If he isn't, he'll end up 5 pixels in the air, which is exactly what happens when roll jumping. |
+ | |||
+ | {{S2Howtos}} | ||
+ | |||
+ | |{{PAGENAME}}]] |
Latest revision as of 11:11, 25 August 2018
(Original guide by MoDule) (S3K fix by ThomasSpeedrunner)
In every main series 16-bit Sonic game, there is a small bug in Sonic's jumping code that assigns him the wrong height and width when jumping while rolling on the ground. Most of the time this goes unnoticed, however occasionally when landing it will cause Sonic to be moved up too far, back into the air and make him temporarily unable to jump. This guide will show how to fix the bug and explain its origin.
Contents
Fixing the bug
Sonic 2, SVN disassembly
Locate the Sonic_Jump routine and comment out two lines as follows:
; loc_1AA38:
Sonic_Jump:
move.b (Ctrl_1_Press_Logical).w,d0
andi.b #button_B_mask|button_C_mask|button_A_mask,d0 ; is A, B or C pressed?
beq.w return_1AAE6 ; if not, return
[...]
;move.b #$13,y_radius(a0) ; set to standing height ;<-- the offending lines
;move.b #9,x_radius(a0) ; and width ;<--
btst #2,status(a0) ; is Sonic rolling?
bne.s Sonic_RollJump ; if yes, branch
move.b #$E,y_radius(a0) ; set to rolling height
move.b #7,x_radius(a0) ; and width
move.b #2,anim(a0) ; use "jumping" animation
bset #2,status(a0)
addq.w #5,y_pos(a0)
return_1AAE6:
rts
; ---------------------------------------------------------------------------
; loc_1AAE8:
Sonic_RollJump:
bset #4,status(a0) ; set the rolling+jumping flag
rts
; End of function Sonic_Jump
Sonic 3 & Knuckles, SVN disassembly
The routine to find here: Sonic_Jump:. For those who prefer using location-based labels, this is sub_117DA:. Scroll down until you see this or something like it (this has SSTs labeled to enhance readability):
move.b default_y_radius(a0),y_radius(a0) ; <-- This line
move.b default_x_radius(a0),x_radius(a0) ; <-- This line
btst #2,status(a0)
bne.s loc_118B4
Comment out or delete the indicated lines.
Things to keep in mind
This bug will be present in any other player objects as well, meaning it needs to be fixed for Tails and Knuckles if they exist, as well as any other characters you may have. Another small thing to note is that this reduces Sonic's hitbox when roll jumping. This shouldn't be much of a problem, though.
The bug explained
The normal procedure for when Sonic jumps is to change him into a ball, reduce his size and due to the height difference move him down a bit, as seen here:
move.b #$E,y_radius(a0) ; set to rolling height
move.b #7,x_radius(a0) ; and width
move.b #2,anim(a0) ; use "jumping" animation
bset #2,status(a0)
addq.w #5,y_pos(a0) ;<-- move to ground
S3K hackers, yours will look something like this:
move.b #$E,y_radius(a0) ; set to rolling height
move.b #7,x_radius(a0) ; set to rolling width
move.b #id_SonicRoll,anim(a0) ; use "jumping" animation
bset #2,status(a0)
move.b y_radius(a0),d0
sub.b default_y_radius(a0),d0
ext.w d0
tst.b (Reverse_gravity_flag).w
beq.s loc_118AE
neg.w d0
loc_118AE:
sub.w d0,y_pos(a0) ; <-- move to ground
The problem lies with the four lines above this code:
move.b #$13,y_radius(a0) ; set to standing height
move.b #9,x_radius(a0) ; and width
btst #2,status(a0) ; is Sonic rolling?
bne.s Sonic_RollJump ; if yes, branch
S3K hackers, yours will look something like this:
move.b default_y_radius(a0),y_radius(a0)
move.b default_x_radius(a0),x_radius(a0)
btst #2,status(a0)
bne.s loc_118B4
The last two lines make sense. If Sonic is already rolling his size and position should be correct, so the code underneath can be skipped. The other two lines would appear to reset Sonic to his normal size, something that doesn't make sense in this context. When jumping normally these two lines have no effect whatsoever, as they are undone shortly afterward. Unfortunately, the code that fixes this problem is skipped when Sonic is already rolling, and he ends up with the wrong height. Now, when he lands on the ground, this code runs:
; loc_1B0AC:
Sonic_ResetOnFloor_Part2:
[...]
btst #2,status(a0) ; is Sonic rolling?
beq.s Sonic_ResetOnFloor_Part3 ; if not, branch
bclr #2,status(a0)
move.b #$13,y_radius(a0) ; reset Sonic's size to standing
move.b #9,x_radius(a0)
move.b #AniIDSonAni_Walk,anim(a0) ; use running/walking/standing animation
subq.w #5,y_pos(a0) ;<-- move Sonic up 5 pixels so the increased height doesn't push him into the ground
What this code does, is reset Sonic to his normal standing height and move him up by 5 pixels when he is in a spinning state. This all makes sense, under the assumption that Sonic is actually using his rolling height. If he isn't, he'll end up 5 pixels in the air, which is exactly what happens when roll jumping.
|Use correct height when roll jumping]]