SHLIM
Active member
About a month ago i was looking for a script that allowed an enemy to face the player while standing still. I couldnt find one so i made one myself. It seems this could be usefull to others so im posting it here! This was the first script i wrote so it might need some extra cleaning up, and i dont think tempB is needed so you can try removing it. But it works! if the player is to the left the enemy will face the left, if the player is up the enemy will face up etc.
It can be used as a enemy action script or easily changed to be a subroutine and called whenever needed, the enemy can be stood still or moving!
It can be used as a enemy action script or easily changed to be a subroutine and called whenever needed, the enemy can be stood still or moving!
Code:
;;; face towards player - by SHLIM
TYA
PHA
TXA
PHA
STA tempx
LDA Object_x_hi,x
STA tempA
LDA Object_y_hi,x
STA tempB ;; may not need this
LDX player1_object
LDA Object_x_hi,x
STA tempC
LDA Object_y_hi,x
STA tempD
LDX tempx
LDA tempC ; horizontal
CMP tempD ; vertical
BCS verticalCompareo
horizontalComparey:
LDA tempC
BPL movingRighto
movingLefto:
LDA #2
STA tempy
JMP +
movingRighto:
LDA #6
STA tempy
JMP +
verticalCompareo:
LDA tempD
BMI movingUpo
movingDowno:
LDA #4
STA tempy
JMP +
movingUpo:
LDA #0
STA tempy
JMP +
+
TXA
STA tempA
TAX
ChangeFacingDirection tempA, tempy
PLA
TAX
PLA
TAY
Last edited: