chronicleroflegends
Member
Hey guys!
Got a neat script I wanted to share in case it is of use to anybody else:
AI Action - Proximity Trigger
This action can be used to give an enemy an area of 'awareness' that can be used to trigger other enemy actions.
So for example, A bat attached to the roof will stay still until you walk underneath it, or an enemy will rush toward you if you get too close to it.
I am sure others could figure out even better uses for it.
Sadly, I am not that great of an ASM programmer, so there are some small bugs:
The horizontal checking distance does not match on the left or right. I am not sure why, but the range on the right extends slightly further.
The Vertical checking distance is only 1 way. I tried to make it check above the enemy as well, but have not had luck so far. However I feel that is the least likely case to run into: to detect the player within a certain distance above an enemy. It also is less sensitive in the vertical checking than horizontal. It seems you can dip into the vertical range for a moment without triggering it.
The code has 2 versions:
Check within a rectangle sideways and below:
Default setup
Horizontal checking only:
Requires you to comment out one small code segment. When you change it to this mode it will always trigger when the player enters the horizontal range, no matter how far above or below they are.
Instructions on using both modes are included in the script.
Thanks again to Mugi for helping me make the script!
As I said before, I am sure there are much better ASM programmers here, so if any of you have any suggestions let me know.
I'll provide it two ways:
You can read the code here:
Download and screenshot included as well
Got a neat script I wanted to share in case it is of use to anybody else:
AI Action - Proximity Trigger
This action can be used to give an enemy an area of 'awareness' that can be used to trigger other enemy actions.
So for example, A bat attached to the roof will stay still until you walk underneath it, or an enemy will rush toward you if you get too close to it.
I am sure others could figure out even better uses for it.
Sadly, I am not that great of an ASM programmer, so there are some small bugs:
The horizontal checking distance does not match on the left or right. I am not sure why, but the range on the right extends slightly further.
The Vertical checking distance is only 1 way. I tried to make it check above the enemy as well, but have not had luck so far. However I feel that is the least likely case to run into: to detect the player within a certain distance above an enemy. It also is less sensitive in the vertical checking than horizontal. It seems you can dip into the vertical range for a moment without triggering it.
The code has 2 versions:
Check within a rectangle sideways and below:
Default setup
Horizontal checking only:
Requires you to comment out one small code segment. When you change it to this mode it will always trigger when the player enters the horizontal range, no matter how far above or below they are.
Instructions on using both modes are included in the script.
Thanks again to Mugi for helping me make the script!
As I said before, I am sure there are much better ASM programmers here, so if any of you have any suggestions let me know.
I'll provide it two ways:
You can read the code here:
Code:
;; AI Proximity Trigger Script:
;; Transition to another state when player comes near
;; By: Chronicler of Legends, help from Mugi
;; NEEDS 2 USER CONSTANTS:
; ENEMY_HPROXIMITY - Distance to trigger when the player enters Horizontally
; ENEMY_VPROXIMITY - Distance to trigger when the player enters Vertically
LDY player1_object ;Get the player object in Y
;; Test to see how far the player is from this monster
; Horizontal Test (LEFT AND RIGHT)
SEC ;Set Carry
LDA Object_x_hi,x ;Get the enemy's origin
SBC Object_x_hi,y ;Subtract player's origin
BCS AIPT_DistanceIsPositive
EOR #$FF ; C flag is clear here,
ADC #$01 ; form two's complement
AIPT_DistanceIsPositive:
; Now you have a number in the accumulator, which shows distance to player
CMP #ENEMY_HPROXIMITY ;;This checks horizontal proximity to player in decimal value
BCC AIPT_insideHProximity
JMP aiProximityNotTriggered
AIPT_insideHProximity:
; Vertical Test (IF YOU ONLY WANT TO TEST HORIZONTAL COMMENT EVERYTHING OUT BETWEEN HERE AND ------
; This checks only for the player BELOW the enemy. Comment this out and use the other for
; 4-way checking
LDA Object_y_hi,y ;Get the player's origin
SBC Object_y_hi,x ;Subtract enemy's origin
; Now you have a number in the accumulator, which shows distance to player
CMP #ENEMY_VPROXIMITY ;;This checks horizontal proximity to player in decimal value
BCC aiTriggerProximity
JMP aiProximityNotTriggered
;--------------------------
JMP aiTriggerProximity
aiTriggerProximity:
ChangeObjectState #$01, #$00
aiProximityNotTriggered:
RTS
Download and screenshot included as well