- Home /
Best way for a shotgun fire?
I'm doing a shotgun weapon, and trying to figure out which is the best way to fire multiple projectiles at once in random directions based on a cone of fire.
The first thing that come to mind is to add multiple raycasts, but there is the problem of randomize them on a given cone of fire, and may lead to a huge chunk of code just for that.
The second thing is to instatiate a gameobject that contains multiple rigidbody projectiles with a script that apply force to them in the random directions.
Any advice on how I should proceed and which way is the best? I'm especially concerned about performance on that one.
Answer by T27M · Oct 01, 2012 at 10:10 PM
I would just cast a ray at your target to use as the hit point, get the distance of the shooter to the target and use that to define your effective range for the gun. For the bullets I wouldn't have any objects as you will probably never see them. Particle effects would be better suited for this. you could easily create a shotgun effect with spread.
Oh and if you wanted you could have a bunch of different hit textures that show the bullet spread based on the distance and also a second particle effect at the hit point if you wanted some shrapnel effects, the amount of attention anyone is going to pay to the hit textures is very little so they don't have to be 100% accurate.
Your answer
Follow this Question
Related Questions
Find a random location, spawn an object there, do it again. 0 Answers
Multiple Cars not working 1 Answer
Mouse pos + raycast 1 Answer
AI Instantiate targets/prefab. (pick target issue) 1 Answer
Grid Placement In Game 2 Answers