I am trying to give an object a velocity spread (e.g. shotgun bullets or particle effect).
//dir is the initial direction
float angle1 = atan(dir.x, dir.z) + spread;
float angle2 = atan(dir.y, abs(dir.z)) + spread;
vec3 xz_dir = vec3(sin(angle1, 0.0, cos(angle2));
vec3 yz_dir = vec3(0.0, sin(angle2), cos(angle2));
vec3 new_dir = vec3(xz_dir.x * yz_dir.z, yz_dir.y, xz_dir.z * yz_dir.z);
new_dir.normalize();
The new_dir
spread works fine in the XY and YZ planes but if there is a Y component in the direction, the spread along the XY plane doesn't work.
I grab two angles from the direction XZ plane and YZ plane and then add a random spread. Then I convert them back into two vectors. Then I combine the two vectors to get the new direction with the added spread.
If I also add a random spread in the XY plane by first grabbing the angle, add a spread, convert to vector:
How would I add this xy vector to the other two vectors?
– codecustard Jul 06 '19 at 07:24