Computer Science Canada Firing bullets - angles - help? |
Author: | Remm [ Fri May 19, 2006 9:20 am ] | ||
Post subject: | Firing bullets - angles - help? | ||
OK, if anyone had seen my earlier program in'A question on shooting...', lets just say its alot better now. However, ![]() I seem to be having problems with multiple angles, like for every move you get a different angle of shot. Having troubles with this. What ive been trying to use is a rise over run (aka (y2-y1) / (x2 - x1) ) to get the angle of fire and then put it into a y=mx+b thing to get the trajectory of the bullet. However, I dont know what to do with the b. example: (This so at any angle x and y, at any angle, can shoot the bullet along that angles line -- will work great for my game ^_^ ... if it works... )
What should i really put for the 800 (b)? and is this a good way to be doing this, or is there a easier way? I looked at the one in the flexable arrays example and got all confused. ![]() Thanks, Remm |
Author: | HellblazerX [ Fri May 19, 2006 10:19 am ] |
Post subject: | |
If you're going to work with angles, you're going to have to learn trig. It is much easier. See, with your method, you find m, which is the slope not angle. There's a difference. Then, you must substitute a set of points into your equation to determine b, which is the y-intercept. Then you plug into an x-value in to get a y-value, can drawing a line to it. With trig, you can just use the cosine and sine functions to get the x and y values. |
Author: | Remm [ Fri May 19, 2006 2:22 pm ] |
Post subject: | |
![]() uhh, you just confused the crap outta me. Im doing sine / trig n all that stuff in school atm, yet i still don get what ur trying to tell me. Agh, im gunna mingle around in my text book until i find out wth to do, will post what i come up with within a day. Wish me luck. ![]() Remm |
Author: | Remm [ Fri May 19, 2006 2:48 pm ] |
Post subject: | |
sorry for double posting but... btw, if anyone could help me with getting the formula going in turning, it would be much appriciated. I now see that im not getting anywhere in slope, so i have to do it the trig way. I see the sind and other commands for it, i jus need to know how to get the angle and how to make THAT shoot. Not seeing how to get the x/y values out of it ![]() |
Author: | TheOneTrueGod [ Fri May 19, 2006 4:16 pm ] | ||
Post subject: | |||
Angles are not the same thing as slope. The equation (x2-x1)/(y2-y1) will not get you the angle between two points, only the slope. You have two options for getting the angle between two points. Use the Math.Angle function included in turing, or create your own Angle function. In order to use it in turing, you have to know a few things about trig first. I'll assume you know the basics, such as sin(0) = 0, sin(90) = 1, cos(0) = 1, and cos(90) = 0, and most importantly, WHY. Allright, with that basic knowledge, you can break up a line segment into two components: its x component, and its y component. --/ | <-- Y component /t_| ^ X component In order to determine the x component, we just take the hypoteneuse (sp?) and multiply it by the cosine of theta (Represented by t in the diagram above.) The y component is similarily determined by multiplying the hypoteneuse by the sine of theta. Syntax in turing is as follows: Radians sin(angle : real) cos(angle : real) tan(angle : real) Degrees sind(angle : real) cosd(angle : real) tand(angle : real) Using this information, lets apply it to a very minor program (That I'm not going to bother testing, so if theres any syntax errors, fix them on your own ![]()
And theres the basics of it ![]() If you want to get into more advanced stuff, there are plenty of good programs in the source code section (Be sure to read the comments before you study the code though, so you can learn which programs aren't good examples ![]() Anyways, good luck |
Author: | Remm [ Fri May 19, 2006 4:29 pm ] |
Post subject: | |
![]() Ack - my turing doesnt have Math.Angle... ?!!? So, any ideas on that 'create your own function'? lol -.- and i KNOW angles arnt same thing as slope, just very poor wording. Quote: I'll assume you know the basics, such as sin(0) = 0, sin(90) = 1, cos(0) = 1, and cos(90) = 0, and most importantly, WHY. uh... yeah... our teacher has yet to tell us why. We jus click the button on calculator an it does stuff - no need to think! I think i'll ask em on monday. |
Author: | TheOneTrueGod [ Fri May 19, 2006 4:44 pm ] | ||
Post subject: | |||
Allright, Number one, here, you can use my function:
Just leave the "created by TheOneTrueGod" line in there, or give me credit somehow and its all good ![]() Anyways, if you plan on doing some programming over the weekend, there are many great tutorials on the web, and there may even be one or two in the [Turing Tutorials] section. Just look around ![]() (And be sure not to use the function unless you know what it does, or else you're not going to understand what your code is doing... not a good thing ![]() |
Author: | Cervantes [ Fri May 19, 2006 5:59 pm ] |
Post subject: | |
Remm wrote: Ack - my turing doesnt have Math.Angle... ?!!? I don't think any of them do, unless v4.1 does. Here's a tutorial by zylum that outlines using trig to move a spaceship. You'll probably find it useful. |
Author: | Remm [ Sat May 20, 2006 9:25 am ] |
Post subject: | |
Thanks guys, i'll try the thing u gave me god, ran it alone and it didint spam errors so, s'all good. Time to put it to use ![]() |
Author: | Remm [ Sat May 20, 2006 6:30 pm ] | ||
Post subject: | |||
Alrighty, thanks to you all, ive gotten it to shoot at least a LITTLE bit properly. I know it still has massive issues, but its a start. I found out what functions are and how to use em per your instructions before using it, since before i was totaly unhinged trying to call up the function. Now, yet another question ![]() How do i shoot more than one bullet at a time? Try turning the SHOOT procedure into a process - thats what i see as a dead end with everything i try. can anyone point me in the right direction as to where i can find it out / any idea for getting the angle thing to work. once i GOT the angle, i was prty blank as what to do next, so i got that strange thing up n running. Dont i have to sine it or somthing? Heres the code so ye kno what im dealin with:
as you can see i've been steering away processes as much as possible. They are evil. |
Author: | Cervantes [ Sat May 20, 2006 6:44 pm ] |
Post subject: | |
Remm wrote: How do i shoot more than one bullet at a time? Try turning the SHOOT procedure into a process - thats what i see as a dead end with everything i try. I'm glad to see you're going to avoid processes. To get this done, you'll need to learn Flexible Arrays. There's an example of just this in that tutorial. You've got quite a steep learning curve right now, it would seem. Good stuff! |
Author: | Remm [ Sat May 20, 2006 7:09 pm ] |
Post subject: | |
yeah but... every time i look at flexable arrays i get very confused and angry at them. Turings help explination of it is horrid to say the least. I kinda know how to do arrays themselves, i guess i'll try to fortify my understanding of arrays then move on to flexables. Thanks again. some day the bullets will acually be shooting at somthing ^_^ |