Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (754) Games in Android Showcase (229) games submitted by our members Games in WIP (842) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
 Home Help Search Login Register
Pages: [1]
 ignore  |  Print
 math question  (Read 1576 times) 0 Members and 1 Guest are viewing this topic.
javatypo

Junior Devvie

 « Posted 2005-03-19 01:37:31 »

ok ill first draw a diagram..

[code]
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

Malohkan

Senior Devvie

while (true) System.out.println("WOO!!!!");

 « Reply #1 - Posted 2005-03-20 01:23:23 »

 1 `Math.atan2(y2 - y, x2 - x);`

How's that?

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

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
javatypo

Junior Devvie

 « Reply #2 - Posted 2005-03-21 20:09:33 »

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
 1  2  3  4  5 `||               (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

 1  2  3  4 `|             (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?

 Games published by our own members! Check 'em out!
Malohkan

Senior Devvie

while (true) System.out.println("WOO!!!!");

 « Reply #3 - Posted 2005-03-23 00:00:48 »

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.

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Pages: [1]
 ignore  |  Print

 DesertCoockie (22 views) 2018-05-13 18:23:11 nelsongames (74 views) 2018-04-24 18:15:36 nelsongames (68 views) 2018-04-24 18:14:32 ivj94 (751 views) 2018-03-24 14:47:39 ivj94 (81 views) 2018-03-24 14:46:31 ivj94 (605 views) 2018-03-24 14:43:53 Solater (97 views) 2018-03-17 05:04:08 nelsongames (178 views) 2018-03-05 17:56:34 Gornova (388 views) 2018-03-02 22:15:33 buddyBro (1048 views) 2018-02-28 16:59:18
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org