instead of bumping one of my month-old posts, i’ll just make a new one
note that i am very bad at math so don’t expect me to know what to do when you say “apply cos and sin to distance”
anyway, there are 2 known issues, 1 is shown, the other isn’t (and i’m about to explain the other)
issue 1 is uh, the raycasts don’t fire at the same time and instead go 1 by 1:
don’t mind the errors in the output, they’re unrelated to shooting
onto issue 2 (feat. horrible explanation)
The raycasts are incredibly inconsistent, the tracers have spread applied onto them very much properly, but the raycasts themselves for some reason spaz out and don’t actually follow along.
i don’t have a video of this sadly (because i noticed this a long time ago) but i think one of you should be able to notice the issue in my beautiful code (Trademark)
elseif tool.GunType.Value == "SHOTGUN" then
local gun = tool
local bullets = tool.Bullets
local flashPart = gun.FlashPart
local shootSound = flashPart.ShootSound
local muzzleFlash = flashPart.Light
local flashImage = flashPart.FlashImage
local BODYSHOT_DAMAGE = gunInfo[tool.Name]["BULLET_DAMAGE"]
local HEADSHOT_DAMAGE = gunInfo[tool.Name]["HEADSHOT_DAMAGE"]
local FIRERATE = gunInfo[tool.Name]["FIRERATE"]
if tool.Shooting.Value then player:Kick("You need more power.") return end
if bullets.Value < 1 then player:Kick("Your manipulation techniques are atrocious.") return end
if bullets.Value > gunInfo[tool.Name]["MAX_BULLETS"] then player:Kick("The underworld calls to you.") return end
tool.Shooting.Value = true
bullets.Value -= 1
shootSound:Play()
coroutine.wrap(function() -- coroutine to prevent yielding
muzzleFlash.Enabled = true
flashImage.Enabled = true
task.wait(0.1)
muzzleFlash.Enabled = false
flashImage.Enabled = false
end)()
local PELLETS = 8
local HORIZONTAL_SPREAD = {min = -0.2, max = 0.2}
local VERTICAL_SPREAD = {min = -0.2, max = 0.2}
local MAX_DISTANCE = gunInfo[tool.Name]["MAX_DISTANCE"]
for pellet=1, PELLETS do
local ran = Random.new()
local spreadX = ran:NextNumber(HORIZONTAL_SPREAD.min, HORIZONTAL_SPREAD.max)
local spreadY = ran:NextNumber(VERTICAL_SPREAD.min, VERTICAL_SPREAD.max)
local direction = (hitPos + Vector3.new(spreadX, spreadY)).Unit
local displacement = direction * MAX_DISTANCE
local origin = flashPart.Position
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {player.Character}
raycastParams.IgnoreWater = true
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
local direction = (hitPos - origin).Unit
local displacement = direction * gunInfo[tool.Name]["MAX_DISTANCE"]
local result = workspace:Raycast(
origin,
displacement,
raycastParams
)
local endPos = nil
if result then
endPos = result.Position
local character = result.Instance.Parent
local humanoid = character:FindFirstChild("Humanoid")
if humanoid ~= players:GetPlayerFromCharacter(character) then
if result.Instance == character.Head then
humanoid:TakeDamage(HEADSHOT_DAMAGE)
DamageIndicatorEvent:FireClient(player, HEADSHOT_DAMAGE, humanoid)
else
humanoid:TakeDamage(BODYSHOT_DAMAGE)
DamageIndicatorEvent:FireClient(player, BODYSHOT_DAMAGE, humanoid)
end
end
else
endPos = origin + displacement
end
-- // TRACERS
local tracer = Instance.new("Part")
tracer.Parent = workspace
tracer.Anchored = true
tracer.CanCollide = false
tracer.CanQuery = false
tracer.Transparency = 0.6
tracer.Color = Color3.new(0.960784, 0.666667, 0.156863)
dService:AddItem(tracer, 0.2)
local tracerLength = (endPos - origin).Magnitude
tracer.Size = Vector3.new(0.07, 0.07, tracerLength)
tracer.CFrame = CFrame.lookAt(origin + (endPos - origin) / 2, endPos)
task.wait(FIRERATE)
tool.Shooting.Value = false
end