In this method, the Sonic goes in enemy direction by the edges of a imaginary rectangle between they.
![Homing Attack - Variant 2 - Quadratic Method Quadraticmethod](https://2img.net/r/ihimizer/img203/7866/quadraticmethod.png)
When the Sonic enter in blue range, the horizontal alignment is activated and the vertical alignment is disabled.
To download the Rom and the Source Code, click here: http://goo.gl/2SH7T
To apply this you need first apply the Homing Attack in Sonic 1 guide.
Now in HA_Move change this:
![Homing Attack - Variant 2 - Quadratic Method Quadraticmethod](https://2img.net/r/ihimizer/img203/7866/quadraticmethod.png)
When the Sonic enter in blue range, the horizontal alignment is activated and the vertical alignment is disabled.
To download the Rom and the Source Code, click here: http://goo.gl/2SH7T
To apply this you need first apply the Homing Attack in Sonic 1 guide.
Now in HA_Move change this:
- Code:
; Recalculating the distance between the Sonic and the object (d1 = x distance / d2 = y distance)
move.w 8(a1),d1 ; move the object x-position to d1
move.w $C(a1),d2 ; move the object y-position to d2
sub.w 8(a0),d1 ; sub sonic x-position of object x-position
sub.w $C(a0),d2 ; sub sonic y-position of object y-position
jsr (CalcAngle).l ; calculates the angle
jsr (CalcSine).l ; calculates the sine and the cosine
muls.w #$C,d1 ; multiply cosine by $C
move.w d1,$10(a0) ; move d1 to X-velocity
muls.w #$C,d0 ; multiply sine by $C
move.w d0,$12(a0) ; move d0 to Y-velocity
Sonic_HA_rts:
rts ; return
- Code:
; vertical alignment
move.w $C(a1),d2 ; move the object y-position to d2
sub.w $C(a0),d2 ; sub sonic y-position of object y-position
move.w d2,d3 ; copy y-distance to d3
muls.w d3,d3 ; vertical distance squared
cmp.w #400,d3 ; is y-distance of Sonic, less than or equal 20 pixels of the object? (20^2=400 // $14^2=$190)
ble.s Ha_GO ; if yes, attack him
clr.w $10(a0) ; if not, stop Sonic's X-velocity
muls.w #5,d2 ; multiply y-distance by 5
add.w d2,$12(a0) ; add y-distance*5 to Y-velocity
rts
Ha_GO: ; horizontal alignment
move.w 8(a1),d1 ; move the object x-position to d1
sub.w 8(a0),d1 ; sub sonic x-position of object x-position
clr.w $12(a0) ; stop Sonic's Y-velocity
muls.w #5,d1 ; multiply x-distance by 5
add.w d1,$10(a0) ; add x-distance*5 to X-velocity
Sonic_HA_rts:
rts ; return
Last edited by OuricoDoido on Fri Feb 04, 2011 12:34 pm; edited 1 time in total