Actions

SCHG How-to

Fix camera y position for Tails

From Sonic Retro

Revision as of 15:09, 22 July 2011 by MoDule (talk | contribs) (Fixing the bug: bugfix corrected/modified; cosmetic changes)

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

Fixing the bug

Step 1

First, locate the ScrollVerti routine and comment out a few lines as follows: <asm>;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
+

</asm>

Step 2

Now add the following at the line indicated above: <asm> moveq #$13,d2 ; set default character height sub.b y_radius(a0),d2 ; get difference to character's actual height neg.w d2 ; we need the inverse

moveq #0,d0 move.b angle(a0),d0 add.w #$40,d0 jsr (CalcSine).l muls.w d2,d0 ext.l d0 asr.l #8,d0 add.w y_pos(a0),d0 ; get player's y position </asm> 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.