In my game, my eneimes are following curved paths. They get the angle by
Code:
vec_set(temp,you.x);
vec_sub(temp,my.x);
vec_to_angle(zombang,temp);
then they get the angle behind them:
Code:
my.tilt = 0;
panopposite = ang(my.pan + 180);
now they compare the angle of the target(either the player if a trace is 0, or their next node(parenthandle) if the trace is >0) against the angle behind them and thier pan. If it is between their pan and thier pan + 180, add 4.5 to their pan. if not, it must be on the right, so subract 4.5.
Code:
if((panopposite >= zombang) && (my.pan <= zombang)){
turnspeed = 4.5 * time_step;
}
else{
turnspeed = -4.5 * time_step;
}
if(my.pan < ang(temp.z - 6) || my.pan > ang(temp.z + 6)){
ang_add(my.pan, vector(turnspeed, 0, 0));
}
however, this does not work. If they can see you, they work, turning left and right. But if you are past the pan + 180 range, but behind a certain angle, they ignore you, turn tward the 0 angle direction, and proceed to walk along it.
This applies not only to the player, but any target they are told to walk to. If the next node is on their left, they ignore it, and just walk forward. If I invert the greater than and less than, and reverse the positive 4.5 and negative 4.5, so that it reads:
Code:
if((panopposite <= zombang) || (my.pan >= zombang)){
turnspeed = -4.5 * time_step;
}
else{
turnspeed = 4.5 * time_step;
}
It will invert the blind side. I don't know what side the code I have posted makes blind, but I do know that it isn't the whole side. A couple of degrees off is where it starts, because the zombies do follow you, until you get far enough to one side. All i want this code to do is find the quickest way to turn to get to the target, while still keeping a curved path.
If anyone can tell me what is wrong with this code, please do so. Or, if anyone has a fix, or a work-around, just let me know.