How to know an angle from a V3 position and V3 direction?

Hi guys,

So I’m working on a shooting game, and I’m working on the guns The MC can use shootguns (as gun class) and we know that shootgun have a cone radius that start from the muzzle of the gun and get bigger. Some people suggested to me to make some pre-made code object, remouve the art and attach the collider to the weapon to solve the problem, however I’m sure that there is a math way to solve the problem.

So here is the var that I have:

Caliber: float from 0 to 1
Position: Vector3 position of the muzzle of the gun
Direction: Vector3 of where the muzzle is pointed.

Now I think that I can use the caliber as a multiply value to know the leght of the cone, but how do I calculate the angle and the arc dimension?

thank you.

It’s a cone so you need two variables :

  • the height (h)
  • the radius (r)

For a shotgun, the “height of the cone” is determined by the velocity (unit/s or m/s) of the bullet drawing a line from the direction you’re aiming at with the weapon.
The radius represents thee spread of the ammunition type for Buckshot and Shotshells because they are composed of pellets (small spherical lead bullets), perpendicular to the height.
The caliber is another thing totally.

You shoot in Vector3(x,y,z) direction, your pellets are going in the same direction and will spread.
Let’s say the velocity is 100 m/s or unit/s and the MAXIMUM spread velocity perpendicular to the shooting direction is 10m/s.

At 1 second, the pellets will be at 100 meters and have spread from a MAXIMUM of 10m radius (20 meters diameter).

The angle of spread is : angle = 2*arctan(10/100) = 11.42 degrees.

So it’s up to you to determine the velocity and the maximum spread velocity or angle of the ammunition (you can use real world value depending on the caliber of course, if you want)

About Shotguns;
About Cones;
About Right Triangle