# 3d - projectile from point A to point B

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

## Recommended Posts

Hello - In my 3D game, I want to fire a projectile (a slow-moving ball of energy) from a ship sitting at Vector A, and I want it to travel a distance of D units, then stop (explode). For direction, I know the Yaw and Pitch of the ship, expressed in degrees. No gravity, no outside forces, just a straight line through 3D space. I thought that I knew enough about vector math to handle this, but I am having trouble. Can someone help get me on track? Thanks in advance!

##### Share on other sites
If the ship only yaws (about the world up axis) and pitches (about the local side axis) you can use spherical coordinates to find the direction vector. There are different ways to do the spherical-to-cartesian conversion depending on which axis is up and which is forward, and which direction the side vector points. So don't expect equations you find online to necessarily work as is; you may have to adapt them to your needs.

Alternately, you could do it with Euler angles. Create a matrix for yaw around world up and a matrix for pitch around the world side vector. Then, if you're using column vectors:

M = yaw * pitch;

Row vectors:

M = pitch * yaw;

The forward vector can then be extracted from M. Plus, you have the rotation matrix available for other purposes if you need it.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 11
• 15
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
634150
• Total Posts
3015827
×