Ducking Size Fix - RetroKoH/S1Fixed GitHub Wiki

(Original guide by Mercury)
Source: ReadySonic
Commit: f720b19

The whole point of ducking is so that you can duck under things. This works okay with regards to most objects like enemies and their projectiles, but Sonic's hitbox remains full-size with regards to some solid objects. We might want it to be shorter in these cases, too. We can do this by using smaller values for Sonic's dimensions if he's ducking (or spindashing) in the solid objects' collision routines.

In _incObj\sub SolidObject.asm, at label loc_FAD0, add this code:

loc_FAD0:
	lea	(v_player).w,a1
	move.w	obX(a1),d0
	sub.w	obX(a0),d0
	add.w	d1,d0
	bmi.w	Solid_Ignore	; if Sonic moves off the left, branch
	move.w	d1,d3
	add.w	d3,d3
	cmp.w	d3,d0		; has Sonic moved off the right?
	bhi.w	Solid_Ignore	; if yes, branch
	move.b	obHeight(a1),d3
	ext.w	d3
	add.w	d3,d2
	move.w	obY(a1),d3
+	cmpi.b	#id_Duck,obAnim(a1)
+	bne.s	.skip
+	cmpi.b	#id_SpinDash,obAnim(a1)	; Only add if Spindash is added
+	bne.s	.skip			; Only add if Spindash is added

+.short:
+	subi.w	#5,d2
+	addi.w	#5,d3

+.skip:
	sub.w	obY(a0),d3
	addq.w	#4,d3
	add.w	d2,d3

Do the same thing in sonic.asm, at label Obj44_SolidWall2:.

Obj44_SolidWall2:
	lea	(v_player).w,a1
	move.w	obX(a1),d0
	sub.w	obX(a0),d0
	add.w	d1,d0
	bmi.s	loc_8B48
	move.w	d1,d3
	add.w	d3,d3
	cmp.w	d3,d0
	bhi.s	loc_8B48
	move.b	obHeight(a1),d3
	ext.w	d3
	add.w	d3,d2
	move.w	obY(a1),d3	
+	cmpi.b	#id_Duck,obAnim(a1)
+	bne.s	.skip
+	cmpi.b	#id_SpinDash,obAnim(a1)	; Only add if Spindash is added
+	bne.s	.skip			; Only add if Spindash is added

+.short:
+	subi.w	#5,d2
+	addi.w	#5,d3

+.skip:
	sub.w	obY(a0),d3
	add.w	d2,d3
	bmi.s	loc_8B48

This final addition should only be applied if the Spindash has been added. In _incObj\sub ReactToItem.asm at ReactToItem: replace this code:

ReactToItem:
	nop	
	move.w	obX(a0),d2		; load Sonic's x-axis position
	move.w	obY(a0),d3		; load Sonic's y-axis position
	subq.w	#8,d2
	moveq	#0,d5
	move.b	obHeight(a0),d5		; load Sonic's height
	subq.b	#3,d5
	sub.w	d5,d3
!	cmpi.b	#aniID_Duck,obAnim(a0)	; is Sonic ducking? (Change from frame check to anim check)
!	beq.s	.short			; if yes, branch
+	cmpi.b	#id_SpinDash,obAnim(a0) ; is Sonic spindashing?; Only add if Spindash is added
+	bne.s	.notducking		; if not, branch; Only add if Spindash is added
+.short:
	addi.w	#$C,d3
	moveq	#$A,d5

.notducking: