OT: I was about to say, suddenly a Nuclear Cheese back on the forums. Welcome back? I guess :V
OT: Well, glad to be back, for whatever capacity of 'back' it'll end up being. Unfortunately I've had not nearly enough time to pay attention to Touhou things lately.
Also, I should probably apologize to everyone with regard to Musuu no Danmaku, but that's getting seriously off topic here so I'll save it for now ...
So I'm back with the same problem.
Nuclear Cheese's solution didn't exactly fix the problem.
Now it stays in an infinite loop going count clockwise. (It used to go one full circle, then go towards the boss.)
I tried fixing it myself. And it got worst. :3
Anyone able to help me?
This is a very insistent problem.
I'm assuming the rest of your code is still the same as you posted in the pastebin. I took another look, and noticed this little item that will also be a problem:
let target_angle=atan2(GetEnemyInfo(enemy_target,ENEMY_Y)-y, GetEnemyInfo(enemy_target,ENEMY_X-x));
... specifically, when you're getting the ENEMY_X, you misplaced your first closing parenthesis - it should be before the "- x" (like when getting ENEMY_Y), not after. Because ENEMY_X is just some value that tells Danmakufu what information you're trying to get, subtracting x doesn't immediately cause it to yell at you (although I'd have no guess as to what it's going to return in this case).
It probably should look like this:
let target_angle=atan2(GetEnemyInfo(enemy_target,ENEMY_Y)-y, GetEnemyInfo(enemy_target,ENEMY_X)-x);
I was never too well versed with player scripts; if I was (or if I had more free time :V) I'd throw together a quick one to try this out myself. Unfortunately I'm stuck with just looking at your posted stuff and trying to figure it out from there.
Another thing to keep in mind: if I remember correctly, Danmakufu's angles returned by atan2 are fixed in a certain range (I forget if it's 0 to 360 or -180 to +180). Because of how your formula is set up, it's possible that certain conditions may yield unusual results. I can't say this is an issue, but at some angle this value will wrap around, causing a seemingly large jump in the angle despite the graphic only rotating a tiny bit more. For instance:
Let's say the current direction is 10, and we calculate the angle to the target as 350. (assuming it returns angles in the range 0-360)
By your script, your shot will try rotating in the positive direction, even though the negative direction is obviously quicker.
A more robust angle comparison code will take this into account, something like this:
// Part 1 - get angles
let my_angle = Obj_GetAngle(obj);
let angle_to_target = atan2(ydiff, xdiff);
// Part 2 - find the angular difference
let angle_difference = angle_to_target - my_angle;
// Part 3 - normalize the angular difference
if (angle_difference > 180)
{
angle_difference -= 360;
}
else if (angle_difference < -180)
{
angle_difference += 360;
}
// Part 4 - rotate
if (angle_difference < 0)
{
my_angle -= 5;
}
else if (angle_difference > 0)
{
my_angle += 5;
}
Obj_SetAngle(obj, my_angle);
(usual disclaimer: pseudo code done from memory, may not be perfect)
In part 3, if the angle is beyond +/- 180, it's really the same as a smaller rotation of the opposite sign (e.g. a 270 degree rotation left is the same as a 90 degree rotation right). By normalizing the difference into this range, we ensure that we're looking at the smaller turn to get to the target angle. This also handles the odd cases caused by the Danmakufu's angle wrapping. Given the same example from above:
my_angle = 10;
angle_to_target = 350;
angle_difference = 340, but is > 180 so it is then normalized to -20
Since the angle difference is now negative, we will rotate in the negative direction.
Also, I'm a bit curious - is there a reason you're looping over all of the enemy IDs? As-is, it's just going to end up taking the last one in the list; are you planning on adding in some conditions to select what enemy to seek later?