I've been trying to code enemies to load into the map with a certain idle state shows all of their angles (whether they see the player or not). Now, I got that to work easily enough, but I also wanted them to pursue the player ONLY if he was in a certain field of vision, so I figured what I could do was get the angle difference between the player and the enemy (i.e, what angle the enemy would have to be at to be facing the player), then add and subtract a number from it, and only have the enemy go into it's seeking AI if it's angle fell between the two numbers that were produced.
ifai AIT1IDLE // if the bad guy is in his idle state
{ ifcansee {
getplayer[THISACTOR].posx PERPLAYER1
getplayer[THISACTOR].posy PERPLAYER2
getactor[THISACTOR].x TEMP1
getactor[THISACTOR].y TEMP2
subvarvar TEMP1 PERPLAYER1
subvarvar TEMP2 PERPLAYER2
getangle TEMP3 TEMP1 TEMP2 // get the angle he'd have to be at to be facing the player
ifvarl TEMP3 0 { mulvar TEMP3 -1 } // and if that angle happens to be less than zero, multiply it by -1
setvarvar TEMP6 TEMP3
setvarvar TEMP7 TEMP3 // store that value in two separate vars for later use
getactor[THISACTOR].ang TEMP5 // get the actor's actual angle
subvar TEMP6 200 // subtract 200 from one of the stored values
addvar TEMP7 200 // and add 200 to another, so this should create an array of values between TEMP7 and TEMP6 where the enemy can see the player
ifvarvarl TEMP5 TEMP7 { ifvarvarg TEMP5 TEMP6 { ai AIT1WALK } } // if the bad guy's angle is greater than the minimum needed angle, but less than the maximum, have him seek the player
This code does, in some small capacity work. Only problem is, it isn't working from the angle I 'need' it to be working from. The bad guy only goes into his seeking AI if I'm behind ( and usually kind of off to the side of) him. If I'm in front of him, he just stands there. The only thing I thought could fix this problem was adding 1024 to the needed angles, thinking that'd flip the values around or something, but he didn't do anything
at all when I did that. Can anyone tell me what I'm screwing up?
EDIT: Nevermind, I think I just got it to work. I don't know if the math was suppose to be like this, but I flipped it around to where the enemy's angle subtracts from the player's angle, and it's working like a charm now.