I have a raycast, that shoots out three different shots. How would I spread them out over an area instead of having them go into a straight line?
Are you using projectiles with rigidbodies ? if so then you can use velocity. There are a few topics for shotguns, where they use particles.
I’m using a raycast function that shoots multiple rays.
So i guess all u need to do is angle the raycast so the spread out. You could use three different transforms to aim the raycast by referencing their transform forward.
I did this for nightfall (http://nightfall.logicwell.com - press “6” to draw shotgun).
Anyhow, atm my approach is to use a sphere (with a changing radius, depending on bloom).
So, the steps are:
- Find the point where your view “hits” an object, a basic raycast like you’re already using most like.
- Determine a radius or “accuracy”.
- Randomly determine a point within a “sphere” area and use radius to scale it (if desired): Unity - Scripting API: Random.insideUnitSphere
- Cast a ray from gun to new point, take the first collision and use that as one of the buckshot pellets.
There are probably better ways, I’m working on making it a bit more predictable so results aren’t too crazy, basically like choosing a pattern or some means of clustering them … anyhow, that was my approach, good luck.
You could try Physics.CheckSphere as an alt to a sphere prefab. You can spawn one at the hit of the raycast.