Computer Science Canada Trigonometry Help - Missle Tracking |
Author: | RedRogueXIII [ Mon Apr 03, 2006 8:32 pm ] | ||
Post subject: | Trigonometry Help - Missle Tracking | ||
Hello, I am having problems getting the projectile to track properly. It is based on angles, finding the angle going to the target then shifting its direction as appropriate to hit it. But : -the projectile seems to not work properly when going straight up, down, left or right. - the projectile turns the longer way to get to the angle, say if it was at 356 and the target angle was 4 then it goes back down clockwise instead of counter-clockwise - When it goes left it just plain messes up, i have no explanation or do not understand why it does this ? Help would be very much appreciated. (there are no images) ::: NOTE : Press Space to launch one missle, the target is always the mouse.
|
Author: | MysticVegeta [ Mon Apr 03, 2006 10:10 pm ] |
Post subject: | |
why not use an if structure to say if difference is > 180 then use counter clockwise else use clockwise i.e. if angle > 180, angle is 360 - angle? PS: I am a complete newbie to trig, i only know grade 10 trig, so I might have a stupid answer |
Author: | TokenHerbz [ Tue Apr 04, 2006 2:45 pm ] |
Post subject: | |
i took grade 11 hardcore trig, but that was 2 years ago :S Anyways, i forgot it all, and i can't run your program cause my turing dosn't have math.distance thing... anyways, i recomend going into the compsci.ca irc channel, and ask a person named """"Ultrahex"""" He helped me with some trig, but, don't bug him, if its a no its a no, or you'll get banned. |
Author: | HellblazerX [ Tue Apr 04, 2006 5:01 pm ] | ||||
Post subject: | |||||
for the portion of code that looks for the angle between the missle and the target, I would suggest you use this piece of code:
Me and my partner made this about a year ago for our final project, so I don't remember much about it. But i do remember that arctand gave us a lot of troubles, so we just used arccosd instead. As for finding the quickest way to turn, try this:
basically, with this code, it calculates the difference between the desired angle and the missle's angle. If the difference is positive, and less than 180, then you should go counterclockwise, which is adding angles, but if it is less than 180, then you should go clockwise, which is subtracting angles. if the difference is negative and less then -180, then you should go clockwise, and counterclockwise if it is greater than -180. The last portion is to wrap around the angle so you don't go greater than 360 or less than 0. As for the projectile not working properly when turned at 90, 180, 270 and 360 degrees, add 0.0001 to the angle you're working with. Because tan of 180 and 360 gives 0, which is a problem when dividing by that, and tan of 90 and 270 degrees is undefined, which is even more of a problem. |
Author: | RedRogueXIII [ Wed Apr 19, 2006 8:25 pm ] | ||
Post subject: | |||
BUMP- Im justing bumping this to show my solution in case anyone has the same problem. (BTW: Added a graphical smoke trail to the missle, to increase performance just comment it out in the main loop)
|
Author: | NikG [ Wed Apr 19, 2006 10:41 pm ] |
Post subject: | |
Wow! That smoke trail is awesome, but a little buggy. What are your plans for this (i.e. what kind of game is this, or are you just experimenting?) |
Author: | RedRogueXIII [ Fri Apr 21, 2006 4:34 pm ] |
Post subject: | |
Well i made it for a game I am/was working on, but now further into it, I doubt if Turing will be able to handle parts of it. Anyways the game is supposed to be similar to the popular Evasive manuvers game, eg topdown ship dog-fighting, but I don't know if I'll finish it in Turing. |
Author: | codemage [ Mon Apr 24, 2006 8:55 am ] |
Post subject: | |
Still goes a bit buggy for some angles. If you get it just right, the missile keeps heading in the opposite direction indefinitely. Out of curiosity, what things are you planning to do that allegedly can't be done in Turing? |
Author: | RedRogueXIII [ Thu Apr 27, 2006 9:55 pm ] |
Post subject: | |
The parts I believe that Turing can't handle at the same time are the scrolling background which i intended to make a map editor for, a pre-set point walls systems, multiple graphics(like being able to handle 10 or more ships on screen + accomodating missles/ lasers/bombs , proper ai navigation around the walls and then i planned to try online multiplayer over the sending and receiving of commands to a server program... and yea its the missles are still buggy, got to fix that... |