Archived

This topic is now archived and is closed to further replies.

math problem

This topic is 5588 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, i have a small math problem that i can''t fiqure out.I am making a game something like ''gorrilas'' or ''worms'', the problem is when i get the angle from the user, i don''t know how to calculate angle in pixels so the shot can be fired at that direction. For example: i know that when the user inputs 45 as the angle, the movement of the shot will be : pixelX + 1 and pixelY + 1 ! But what if the user inputs 25 as the angle? It would be something like this pixelX + 3 and pixelY + 1 or something. What i want is to calculate that. Maybe this is not the best way to do this if you know the proper way or a better one please tell me. The inputs are :''power and angle'' i want in some way for the shot to be fired at the right angle. (sorry for the grammar or spelling)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It''s all basic trigonometry and physics. Here''s a diagram:

/|
/ |
C / | A
/ |
/ |
a /_____|
B

A = sin(a)*C
B = cos(a)*C

The ''power'' that you want becomes side C. You use sine and cosine to find the up (A) and forward (B) vectors from C. The up vector (A) will be affected by gravity, but the forward vector (B) will not be.

Share this post


Link to post
Share on other sites
Since you are talking in degrees and sin, cos accept arguments in radians you'll also need to convert from degrees to radians...

360 deg = 2 * PI radians

so radians = ( degrees / 180 ) * PI



[edited by - Paradigm Shifter on August 29, 2002 7:17:19 AM]

Share this post


Link to post
Share on other sites
This is all nice and correct but when i try to convert the numbers to pixels it get confusing. For example i do A and B with 45 angle and the result is A=B which is correct. But when i convert A to pixelsY and B to pixelsX i want the movement X Y (loop x++ y++) of the shot to finish in equal times. Anyway the point is that i get confused with too much math problem solving, i haven''t done trigonometry for 5 years.
Can anyone show a piece of code that gets power and angle from the input and fires a shot in that direction including the force of gravity, im sure its not very hard to do but im just a noob at game programming(this is my first game).

Sorry for being such a pain, any help is more than just thanks!

Share this post


Link to post
Share on other sites
Use floating point values and convert to ints for drawing purposes only.

Look into vectors (maths not C++), there''s lots of resources here or on the web.

Also look into ballistics, that''s the area of maths you are dealing with.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

Share this post


Link to post
Share on other sites