ID:148652
 
This i part of the AI for a racing game. I have a series of points around the track and the AI finds the angle to the next point and adjusts its angle. It seems to work until the next point is to the left of its current position. Here is the part that most likely has the problem.

proc Get_Dist(atom/A, atom/B) return sqrt( ( A.x - B.x )**2 + ( A.y - B.y )**2 ) Get_Beacon(var/number) for(var/obj/AI_beacon/BEACON as obj in world) if( BEACON.number == number ) return BEACON AI_Loop() if( Get_Dist( src, Get_Beacon( src.beacon ) ) <= 4 ) var/obj/AI_beacon/next_beacon = Get_Beacon( src.beacon+1 ) src.wanted_angle = arcsin( ( next_beacon.y - src.y ) / Get_Dist( src, next_beacon ) )
It successfully gets through the first four points, but after that the car keeps running into the right wall.

[edit] I'm not positive that this is what it does, but it should go at an angle of (approxiamately) 135 degrees (northwest) but instead it goes at an angle of (exactly) 45 degrees (northeast). Essentially, I made the AI car the origin, and found what quadrant the next beacon would lie in, but that doesnt seem to work either. I tried arctan() but that did the same thing.
I'm no math whiz, but from similar posts on here, I gather what you need to use is arctan(), not arcsin(). As there is no arctan() proc in BYOND, you'll have to make your own. Fortunately, though, I was able to dig up an old post by LummoxJR that may help you do this:

[link]

If that doesn't work, you'll have to wait until someone with more math skill logs on.

~X
In response to Xooxer
The only diffrence arctan() would make is that I don't have to find the distance between the car and the next beacon. Using arctan() it still has the same problem.
It looks like your problem is with your Get_Beacon proc. After all the beacons have been reached, there is nothing telling the get_beacon code to reset. Try something like this:
// Just a little bit of code to cache the beacon list.
// You may want to change this.
var
list/Beacons
MaxBeac
MinBeac

proc/GetBeacons()
if(Beacons) return Beacons
Beacons = list()
for(var/obj/AI_beacon/b in world)
Beacons += b
if(b.number > MaxBeac) MaxBeac = b
if(b.number < MinBeac||!MinBeac) MinBeac = b
return beacons

proc/GetNextBeacon(/obj/AI_beacon/cur_beac)
var/list/beacons = GetBeacons()
var/next_beac = cur_beac.number+1
if(next_beac > MaxBeac) next_beac = MinBeac
return GetBeacon(next_beac)

proc/GetBeacon(number)
var/list/beacons = GetBeacons()
for(var/obj/AI_beacon/b in beacons)
if(b.number==number) return b

I really have no clue if this code will work, but I am just about 100% sure that's why you are having problems.
In response to Ebonshadow
Well, that is part of the problem, but not the solution. There are about 15 beacons, and it doesn't reach the fifth one successfully, therefore it wouldn't have any problems in resetting. Thanks for the help though, I'll have to do something like that eventually.
In response to Xooxer
I think that arcsin() or arccos() would work better, because using arctan() could result in division by zero. arcsin() and arccos() could have division by zero, but that would only occur if the distance between the AI car and the next beacon is zero.
In response to OneFishDown
Well, you seem to know what you're doing with these math procs, so I'll take you're word for it regarding the arctan() situation. I do realize that division by 0 is a no-no in mathematics, I was just not aware that this would happen for you if you used arctan(), else I wouldn't have suggested it. Like I said, I'm no math whiz.

I really should continue my education in mathematics, especially if I ever want to get anywhere in programming. I doubt I'll be utilizing the more complex concepts in BYOND, though, so I can take my time catching up. At least I can add and subtract! :)

X=(X++)-X