I’ve been attempting to perfect my shotgun spread.
As of now, I’ve been having trouble implementing any sort of spread.
I’m not sure where I’d put the spread, I have a fairly good grasp on how I’d get the spread though.
Disclaimer: This is for a projectile-based gun-system, which uses both TweenService and Raycasting
local ray = Ray.new(tool.Object.FirePart.Position,MouseHit.LookVector * 300)
TweenS:Create(Shard,TweenInfo.new(1,0,0),{CFrame = HRP.CFrame + MouseHit.LookVector * 300 }):Play()
2 Likes
I’ve created shotguns before, and it’s pretty simple.
Though can you elaborate on what you mean by where you’d put the spread? Do you mean where you’ll put the logic for the spread at or how you’re going to add the spread onto the bullets?
local pelletCount = 7 --The number of pellets you want being shot
local maximumOffset = 1 --The maximum number of studs that the bullets will offset at
local RNG = Random.new()
for i = 1, pelletCount do --Create a loop that repeats itself based on the amount of pellets being shot
local pelletSpread = Vector3.new(RNG:NextNumber(-maximumOffset, maximumOffset), RNG:NextNumber(-maximumOffset, maximumOffset), RNG:NextNumber(-maximumOffset, maximumOffset)) --Create a Vector3 that consists of a randomization of all the axes.
local ray = Ray.new(tool.Object.FirePart.Position,(MouseHit.LookVector + pelletSpread) * 300) --Create an equation of Mouse.Hit.LookVector + the pelletSpread.
end
3 Likes
How would I use the ray variable here for the pellets? Sorry, I haven’t really done much raycasting. The type of raycasting I usually do does not use Ray instances.