I have a 3D world and I have a gun who's position is defined by X,Y,Z which fires a bullet in a straight line with a direction defined by X, Y, Z towards a target who position is defined by X,Y,Z with a spherical bounding volume.
How can I calculate if the bullet intersects the sphere?
Does the bullet fly in a straight line or is there gravity in some direction? Assuming a straight line, that the weapon's position is $(X_1,Y_1,Z_1)$, the velocity of the bullet is $(V_x, V_y, V_z)$, the center of the sphere is $(X_2,Y_2,Z_2)$, and the radius of the sphere is R, then the bullet's path is given by $x= X_1+ V_xt$, $y= Y_1+ V_yt$, $z= Z_1+ V_zt$ and the sphere by $(x- X_1)^2+ (y- Y_2)^2+ (z- Z_2)^2= R^2$. Put the x, y, z equations of the bullet into the sphere equation and solve the quadratic equation for t. If there is no positive, real solution, the bullet misses the sphere. If there is a double positive root the bullet grazes the sphere, and if there are two positive solutions, the bullet passes through the sphere. (If there is one positive and one negative solution, the weapon's position is inside the sphere!)