math question

ok ill first draw a diagram…


0 degrees
|
|                        
| 
|                      (x2,y2)
|  (x,y)
|_______________ 90 degrees

so up there i have two known points, and i want to find the angle at which (x,y) must be rotated to be facing (x2,y2). this is for my car racing game, im trying to line up (just the human) car at to the finish line. what im doing is finding the mid point of the finish/starting line, then i give it an offset (so thats is somewhere before the starting line) then i calculate the angle to the point on the starting line where the car will be perdendicular to.

i was using something like the rule cos(theta) = y/x, but for some reason that doesnt really work to great. it works if i calculate the angle the car must travel to hit the midpoint, but if i try and move that point, then for some reason it doesnt give me the expected results.

thanks for any help :)
Math.atan2(y2 - y, x2 - x);

How’s that?

That’s the angle of the first guy to the second guy.

nice okay i got that working, but now i have another problem…

im using the same method of lining up cars to lines in my game for the admin cars, so what i did was precalculate an array of angles so that as the ai car moved along and hit certain points it would take up a new angle. the track is “circle” which is made up of lines, and is drawn as a polygon, so if u can imagine that… lol. the problem here is that if a line has an opposite slope to another line, then the angle will be the same.

so to draw


|
|               (x2,y2)
|  
| (x1,y1)
|_________

the angle here is say 30 (degrees) and the car should in theory be facing at (x2,y2) and accelerate that way when it accelerates


|             (x1,y1)
|
|(x2,y2)
|__________

here the angle works out (if x1 and y1 become x2 and y2 respectively) to the same as the above example, so im wondering how to get what that angle would be if u took into consideration that the begining angle is zero.

or maybe if i just added that angle value to what ever is was before it hit that line?

thanks alot for any comments or whatever about this.

if the two points are the same, then why do you need to know the angle between them? That’s a silly question that you should never even ask. If you’ve reached your destination, you need a new destination.