Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a 2D projectile code sample working, but would like to extend it to 3D. How would I calculate the initial velocity of the Z-axis? At the moment, I've got:

initVel.X = (float)Math.Cos(45.0);
initVel.Y = (float)Math.Sin(45.0);

How would I convert this to work in 3D, and add the initial velocity for the Z-axis?

In my example, X is across, Y is up down and Z is going into the screen. I also normalize the vector and multiply it by the speed.

share|improve this question
Although you have a trigonometric answer below, if you intend to dive deeper into 3d, you might want to consider trading in the trigonometric approach to 3d problem solving in favor of a linear algebra approach... Much less headache and much more versatile in the long run. – Steve H Mar 6 '11 at 22:21
Thanks for the suggestion. I'm using vectors to perform the motions, but since I only need to call this very few times, I figured it would suffice. To clarify, by a linear algebra approach, do you mean using Matrices and Quaternions? – Skoder Mar 6 '11 at 23:35
up vote 3 down vote accepted
double ZAdjust = Math.Cos(XZAngle);
initVel.X = (float)(Math.Cos(XYAngle) * ZAdjust);
initVel.Y = (float)(Math.Sin(XYAngle) * ZAdjust);
initVel.Z = (float)Math.Sin(XZAngle);
share|improve this answer
Thanks for the help. – Skoder Mar 6 '11 at 19:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.