Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (523)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
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 799 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..

[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 Smiley


Offline 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!
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
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?

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
GameLizard.com
Play Rimscape!    |    Play Conquer!
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

SHC (23 views)
2014-11-25 12:00:59

SHC (21 views)
2014-11-25 11:53:45

Norakomi (19 views)
2014-11-25 11:26:43

Gibbo3771 (22 views)
2014-11-24 19:59:16

trollwarrior1 (36 views)
2014-11-22 12:13:56

xFryIx (74 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (41 views)
2014-11-12 21:09:33

kovacsa (67 views)
2014-11-07 19:57:14
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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
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!