I am currently working on creating a gun system with random bullet spread, however when I look in different directions the bullet holes and trails spawn in weird places. First image is how I want the spread to work, second image is bugged where spread doesn’t work left the right. Below I have attached an image of my code. Any help would be appreciated
When posting code on the forum, don’t post an image of the code, just paste it directly into the thread using Code Tags .
When you create the direction Vector by adding the spread, you don’t turn the spread values to face the same way as the camera.
So how should I set the spread values?
Instead of just adding the base value, you can use Transform.TransformPoint to turn the value into World space from local.
I guess I’m just struggling on where to actually implement the spread if it is not within the direction vector. And if it is within the direction vector how would I apply the Transform.TransformPoint? I’ve tried
Vector3 _spread = transform.TransformPoint(x, y, 0f);
Vector3 direction = fpsCam.transform.forward + _spread;
I’ve also tried
Vector3 direction = transform.TransformPoint(x, y, 0f);
Both methods ended up with bullets going in very strange directions.
With my current code when I get rid of the spread the bullets work just fine they just go perfectly towards the center of the screen.
Just add to the direction vector from Random.insideUnitSphere
scaled down by a bunch.
Optionally renormalize it after the add… hose 'em down!!
This worked perfectly, thank you so much!