Skip to main content
GameDev.net gamedev.net
🔒 Locked

Bullets directional path

Started by Anddos Jan 4, 2010 at 11:17 PM 3 replies 900+ views
Original Post
Anddos
Anddos
is it normal to fire the bullet direction like this using sinf and cosf to make the bullets move in the direction the ship is, can you use it in 3d programming for the same thing ?
:)
monkey_32606
monkey_32606
You're going to have to give them a direction vector eventually. Given that polar coordinates (angle and distance) are converted to cartesian coordinates (x and y) using sine and cosine, I expect most people are going to say yes. Those same transforms also work for 3 dimensions.
Quote: Michael TanczosCut that shit out. You shouldn't be spying on other people.. especially your parents. If your dad wanted to look at horses having sex with transexual eskimo midgets, that's his business and not yours.
Anddos
Anddos
so what happens with the z axis for sinf and cosf? , if they are only for x,y
:)
Buckeye
Buckeye
If your programming language has a vector class or set of functions, you don't need to do the trig.

Given a vector for the base_position_vector of the ship and a unit vector in the direction the ship is heading when the bullet is fired, the bullet's location is:

base_position_vector + speed*time*direction_unit_vector

If you need more specific information, you'll have to be more specific about your needs.
Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly. You don't forget how to play when you grow old; you grow old when you forget how to play.
Zakwayda
Zakwayda
There is a 3-d equivalent to 2-d polar coordinates - spherical coordinates - that uses two angles instead of just one and can specify any direction in 3-d. However, as Buckeye said, if you have a forward direction vector for your ship, you already have all the information you need, so there's really no reason to use trig for this. (And if you're *rendering* your ship, which you presumably would be, then somewhere you must have a transform for it, in which case you have the forward direction vector.)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.