I need help with a Top Down Enemy AI that has a patrolling and aggression state. I coded everything from another forum post to a T and my enemy AI just isn’t moving at all. Here’s what the code looks like
EVENT 1:
“If monster distance to player is below 250 and PlayerInRange is FALSE”
→ Change PlayerInRange to TRUE
But look at the very next event:
EVENT 2:
“If monster distance to player is below 450 and PlayerInRange is TRUE”
→ Change PlayerInRange to FALSE
…
Don’t these cause a certain type of loop? Every time event 1 happens, event 2 happens after it. Event 1 always fulfills the conditions of event 2. Every time event 1 changes PlayerInRange to TRUE, event 2 changes it back to FALSE immediately after (before anything happens on screen).
Therefore the condition “PlayerInRange is TRUE” in “Player Spotted” can never be satisfied. It’s never true, because even if it was previously, event 2 already changed it back to false.
If you wanna fix it, I think you’ll have to make the conditions of event 2 more strict. How about:
EVENT 2:
Conditions:
If monster distance to player is below 450 (this condition can maybe be removed all together)
INVERTED If monster distance to the player is below 250
PlayerInRange is TRUE
Actions:
Change PlayerInRange to FALSE
(This could possibly be fixed just by changing the order on event 1 and event 2. You can try switching their places).
Hope hope I’m correct. Didn’t really think it through
In that one very place where you should not have RandonFLOATInRange
You have it
Remove float
Just so you understand
RandomInRange(1,6)
You have chance to roll out either 1 - 2 - 3 - 4 - 5 or 6
HOOOOOOOOOOOOOOOOOWEVER
RandomFloatInRange(1,6)
1 - 1.00000000000001 - 1.121654651868 - 2.004 up to 6
So you are rolling numbers WITH decimals
And trust me 1 is not equal to 1.000000000001 neither it is to 1.4444
And so go on
Also you should use for each object event i think for your enemies and their timers
ALSO for each enemy you should make variable called TimeRNG
Set it to RandomFloatInRange(2.5 , 3.5)
And now you check if PatrolAI timer of Monster 2 is greater than Monster2.TimeRNG
Cause right now you are spamming values which timer checks
Like imagine you are trying to place your bet on number and check if whatever number rolled is greater than the one on which you bet
But numbers are rolling constantly not stopping at all
So in a blink of second your number would fit your check
And lastly same story as above for PatrolAI2 timer