PDA

View Full Version : Math :) shooting by angle



WiZz
07-06-2004, 07:47 PM
hello, for example if my sprate is rotated 45 degrees to left, how to make Bullet to fly 45 degrees angle. well i don't know how to explain, but this typo of shooting was in Horrorween, Star Trek: red alert, crimsonland and others top down shooters :)

Traveler
07-06-2004, 08:38 PM
usually a sprite moves by changing x and y values.
Using a combination results in the desired direction.

In your case increasing x and y at the same time, with the same values will give you a 45 angle direction.

WiZz
07-06-2004, 08:52 PM
I know this :), but if sprite is rotated by 30 degree? or 15, or 17... how to count this value?

Paulius
07-06-2004, 09:33 PM
XStep:= cos(Angle);
YStep:= sin(Angle);
Add those steps to your x, y, just remember to make x and y real numbers.

WiZz
08-06-2004, 08:29 AM
Thank's Paulius :)

WILL
09-06-2004, 01:09 AM
Here is a link to my little cheat sheet (http://terraqueous.f2o.org/dgdev/viewtopic.php?p=4184#4184) I put up some time last year. It might help you our a bit with the maths. Thing is with the cos and sin functions in Pascal is that they take in vales in radians not degrees. So you'll have to convert those too. My cheat sheet will show you how though.

If you wanted to have a 'gravity' you'd have to add a 1.000 to 0.001 value(or whatever values work with your game best) and apply it to your Y Velocity(or in Paulius' example StepY). There are some other tricks to mess with the physics of your moving objects in your game, but this is enough to get you started at least.