• News

• Industries

• Learning & Support

• Community

• Marketplace

# Random Unit Vector in Cone in Radians

Hey all! I am trying to figure out the best way to calculate a projectile “spread” system that uses 2 floats to calculate the cone half angle. I am trying to use 2 float values that represent the distance and accuracy.

Honestly, I am not sure how calculating the cone half angle should even work… So I am not really sure how to ask the right question… I know this has to do with inverse tangents but that is way beyond me…

The simple way to put it is that I want the “spread” of the projectiles to match the accuracy at the given distance…?
Lets say accuracy reflects a cone radius where accuracy “50” = a radius of 1 meter from center and accuracy “100” = a radius of 1 centimeter from center.
now to bring range in… at “X” distance the above calculation is correct…

Here’s where I’m at so far…
(Note that the mapped range for accuracy and range are just values I was playing around with. What I do know is that at 5 meters away I like the accuracy mapping. I just don’t know how to go about altering the value of the accuracy depending on the range…?

I’ve also created a super cheesy diagram to further illustrate what I am picturing.

A = Accuracy 90% Range = 500m
B = Accuracy 50% Range = 500m
C = Accuracy 90% Range = 700m
D = Accuracy 50% Range = 700m

Each of the above examples would have a different value for the “cone half angle in radians” - which is what I am trying to solve for…
Any input would be amazing!

One idea…
Store a float curve for each weapon.