Difference between revisions of "Fix camera y position for Tails"
From Sonic Retro
(Moving to the correct place and removing invalid redirect) |
m (Text replacement - "\[\[Category:SCHG How-tos.*" to "") |
||
(7 intermediate revisions by 3 users not shown) | |||
Line 6: | Line 6: | ||
==Fixing the bug== | ==Fixing the bug== | ||
+ | ===Step 1=== | ||
First, locate the '''ScrollVerti''' routine and comment out a few lines as follows: | First, locate the '''ScrollVerti''' routine and comment out a few lines as follows: | ||
− | <asm>;sub_D77A: | + | <syntaxhighlight lang="asm">;sub_D77A: |
ScrollVerti: | ScrollVerti: | ||
moveq #0,d1 | moveq #0,d1 | ||
− | + | move.w y_pos(a0),d0 | |
; <-- add something here | ; <-- add something here | ||
Line 23: | Line 24: | ||
; subq.w #5,d0 ; subtract difference between standing and rolling heights | ; subq.w #5,d0 ; subtract difference between standing and rolling heights | ||
;+ | ;+ | ||
− | </ | + | </syntaxhighlight> |
+ | ===Step 2=== | ||
Now add the following at the line indicated above: | Now add the following at the line indicated above: | ||
− | <asm> moveq #$13, | + | <syntaxhighlight lang="asm"> moveq #$13,d2 ; set default character height |
− | sub.b y_radius(a0),d0 ; get difference to character's actual height | + | sub.b y_radius(a0),d2 |
− | + | sub.w d2,d0 ; get difference to character's actual height | |
− | + | </syntaxhighlight> | |
− | </asm> | + | ===Step 3=== |
+ | Our new code relies on the character's y_radius being set, which it normally isn't, at this point, so let's fix that. Find '''InitPlayers'''. Here, we'll initialise the characters' y_radius before they do so themselves. Find this line: | ||
+ | <syntaxhighlight lang="asm"> move.b #ObjID_SpindashDust,(Sonic_Dust+id).w ; load Obj08 Sonic's spindash dust/splash object at $FFFFD100 | ||
+ | </syntaxhighlight> | ||
+ | Insert this instruction under it: | ||
+ | <syntaxhighlight lang="asm"> move.b #$13,(MainCharacter+y_radius).w ; Set Sonic's y-radius | ||
+ | </syntaxhighlight> | ||
+ | Do this again with the same instruction under '''InitPlayers_Alone'''. | ||
+ | ===Step 4=== | ||
+ | New to initialise Tails' y-radius. Under '''InitPlayers_TailsAlone''', find this instruction: | ||
+ | <syntaxhighlight lang="asm"> move.b #ObjID_SpindashDust,(Tails_Dust+id).w ; load Obj08 Tails' spindash dust/splash object at $FFFFD100 | ||
+ | </syntaxhighlight> | ||
+ | Under it, insert this instruction: | ||
+ | <syntaxhighlight lang="asm"> move.b #$F,(MainCharacter+y_radius).w ; Set Tails' y-radius | ||
+ | </syntaxhighlight> | ||
+ | ===Step 5=== | ||
+ | One last thing: '''ScrollVerti''' runs before '''InitPlayers'''. We don't want that. Under Level_TtlCard, find this instruction: | ||
+ | <syntaxhighlight lang="asm"> bsr.w InitPlayers</syntaxhighlight> | ||
+ | Move it just above this instruction: | ||
+ | <syntaxhighlight lang="asm"> jsrto (DeformBgLayer).l, JmpTo_DeformBgLayer | ||
+ | </syntaxhighlight> | ||
+ | Now '''InitPlayers''' will execute before '''ScrollVerti''', making everything work as it should. | ||
+ | |||
With this the camera will always have the right position for everyone. | With this the camera will always have the right position for everyone. | ||
==The bug explained== | ==The bug explained== | ||
Whenever a character's height changes, so does their y position. Jumping reduces the height and the character gets moved down a few pixels to the ground. The original code only took Sonic's height change into account, so when it compensates for the height change from jumping or rolling it does so incorrectly for Tails. | Whenever a character's height changes, so does their y position. Jumping reduces the height and the character gets moved down a few pixels to the ground. The original code only took Sonic's height change into account, so when it compensates for the height change from jumping or rolling it does so incorrectly for Tails. | ||
+ | |||
+ | {{S2Howtos}} | ||
+ | |||
+ | |{{PAGENAME}}]] |
Latest revision as of 11:11, 25 August 2018
(Original guide by MoDule)
Due to an oversight in the camera system in Sonic 2, when Tails goes into a roll on the ground the camera will seem to jerk upward by a few pixels. The camera will also generally be slightly lower when playing as Tails.
This guide will show how to fix this.
Contents
Fixing the bug
Step 1
First, locate the ScrollVerti routine and comment out a few lines as follows:
;sub_D77A:
ScrollVerti:
moveq #0,d1
move.w y_pos(a0),d0
; <-- add something here
sub.w (a1),d0 ; subtract camera Y pos
cmpi.w #-$100,(Camera_Min_Y_pos).w ; does the level wrap vertically?
bne.s + ; if not, branch
andi.w #$7FF,d0
+
; btst #2,status(a0) ; is the player rolling?
; beq.s + ; if not, branch
; subq.w #5,d0 ; subtract difference between standing and rolling heights
;+
Step 2
Now add the following at the line indicated above:
moveq #$13,d2 ; set default character height
sub.b y_radius(a0),d2
sub.w d2,d0 ; get difference to character's actual height
Step 3
Our new code relies on the character's y_radius being set, which it normally isn't, at this point, so let's fix that. Find InitPlayers. Here, we'll initialise the characters' y_radius before they do so themselves. Find this line:
move.b #ObjID_SpindashDust,(Sonic_Dust+id).w ; load Obj08 Sonic's spindash dust/splash object at $FFFFD100
Insert this instruction under it:
move.b #$13,(MainCharacter+y_radius).w ; Set Sonic's y-radius
Do this again with the same instruction under InitPlayers_Alone.
Step 4
New to initialise Tails' y-radius. Under InitPlayers_TailsAlone, find this instruction:
move.b #ObjID_SpindashDust,(Tails_Dust+id).w ; load Obj08 Tails' spindash dust/splash object at $FFFFD100
Under it, insert this instruction:
move.b #$F,(MainCharacter+y_radius).w ; Set Tails' y-radius
Step 5
One last thing: ScrollVerti runs before InitPlayers. We don't want that. Under Level_TtlCard, find this instruction:
bsr.w InitPlayers
Move it just above this instruction:
jsrto (DeformBgLayer).l, JmpTo_DeformBgLayer
Now InitPlayers will execute before ScrollVerti, making everything work as it should.
With this the camera will always have the right position for everyone.
The bug explained
Whenever a character's height changes, so does their y position. Jumping reduces the height and the character gets moved down a few pixels to the ground. The original code only took Sonic's height change into account, so when it compensates for the height change from jumping or rolling it does so incorrectly for Tails.
|Fix camera y position for Tails]]