Computer Science Canada Trouble Shooting trig |
| Author: | BenLi [ Wed Apr 26, 2006 2:48 pm ] | ||
| Post subject: | Trouble Shooting trig | ||
im trying to make a program to shoot a projectile and calculate the angle in which it was fired at. I get a error message saying "quit #100", help PLZ
|
|||
| Author: | HellblazerX [ Wed Apr 26, 2006 3:03 pm ] | ||
| Post subject: | |||
sounds like you don't know how to use arcsind. Arcsind takes the original sine value, and returns the angle in degrees. So, originally, to determine the y-value, we have sine(theta) * hypotenuse. So, to find theta, we use sine inverse (y/hypotenuse). So, replace the line where you used arcsind with this:
The if construct is there incase the hypotenuse was 0, and you can't divide by 0. Btw, you should slow down the speed of your projectiles, cuz they're very hard to see. Other than that, a great program. Are you planning to do anything with it? |
|||
| Author: | HellblazerX [ Wed Apr 26, 2006 3:09 pm ] | ||
| Post subject: | |||
Sry, I forgot this in my first post. Add this piece of code after the arcsind function:
Because arcsind only works for half of the circle, from -90 to 90, this part checks if we're working with the other half, and if so, changes the angle to the correct one |
|||
| Author: | BenLi [ Wed Apr 26, 2006 3:09 pm ] |
| Post subject: | |
thanks, i asked my comp sci teacher for the syntax for cos inversion, and he just said arcsind... maybe i should've asked how to use it and yes, im using it for a gunbound like game, i haven't put in gravity yet though, any idea how to do that? |
|
| Author: | Tony [ Wed Apr 26, 2006 3:12 pm ] |
| Post subject: | |
for gravity, just accelerate everything downwards by a constant during each tick of your game loop. |
|
| Author: | BenLi [ Wed Apr 26, 2006 3:15 pm ] |
| Post subject: | |
But you would increase the grav value for every time it loops right? i tried taht, didn't look good |
|
| Author: | Cervantes [ Wed Apr 26, 2006 5:17 pm ] |
| Post subject: | |
No. Gravity is constant. (Assuming you don't care about the negligable amount by which the force of gravitation attraction decreases as you move up a couple of metres) |
|
| Author: | Clayton [ Wed Apr 26, 2006 7:01 pm ] | ||
| Post subject: | |||
for gravity you could do something like this
something like that will create a more realistic jump with gravity (im not 100% sure that that will run perfectly, dont quote me on that one) experiment with it and see what you can come up with |
|||