Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (592)
Games in Android Showcase (168)
games submitted by our members
Games in WIP (645)
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 902 times)
0 Members and 1 Guest are viewing this topic.
Offline javatypo

Junior Devvie

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

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 Smiley

Offline Malohkan

Senior Devvie

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

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

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
Play Rimscape!    |    Play Conquer!
Offline 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
|               (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)

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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline 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
Play Rimscape!    |    Play Conquer!
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

deepthought (14 views)
2015-06-30 15:39:44

deepthought (17 views)
2015-06-30 15:39:09

deepthought (22 views)
2015-06-30 15:36:52

Za\'Anzabar (17 views)
2015-06-29 05:44:54

TritonDreyja (34 views)
2015-06-24 17:10:40

CopyableCougar4 (29 views)
2015-06-23 00:34:45

BurntPizza (34 views)
2015-06-21 20:36:46

cookiecompiler (78 views)
2015-06-11 15:42:53

cookiecompiler (41 views)
2015-06-11 15:41:14

NegativeZero (68 views)
2015-06-11 09:49:18
How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14 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‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!