Hello, I already did fov based turret base. But I still have one issue. Spread, Idk how to make it. Anyone can explain? My turret have Attachment1 at barrel and just sending ray to character humanoidrootpart. On ray hit it’s just spawning invisible part on hit position, and putting attachment 2 inside. It’s not shooting straight.
It looks like it’s shooting straight. What are you trying to fix?
But it’s not , I wanna make recoil which offset ray end position. it would be easier if it’s was straight, but it’s not and I don’t wanna to. I just explained how my turret works for better method
Hey, I have some bullet spread code that works!
I used it on a gun game I was developing, and it is decently customizable.
local SpreadMultiplier = 10 -- DO NOT CHANGE THIS
local Current_Spread = 35 -- Feel free to change this, higher number = larger spread.
local MaxRange = 10000 -- This is just how far the raycast travels. Change it to whatever you want.
function Raycast()
local NewRay = RaycastParams.new()
local RayOrigin = Camera.CFrame.Position -- Replace this with your ray origin
local RayDiretion = Camera.CFrame.LookVector*500 -- Replace this with your ray direction vector
-- Dont change any of this.
local BulletOffset = CFrame.new(RayOrigin, (RayDiretion*500))*CFrame.Angles(math.rad(math.random((-Current_Spread/100)*SpreadMultiplier, (Current_Spread/100)*SpreadMultiplier)), math.rad(math.random((-Current_Spread/100)*SpreadMultiplier, (Current_Spread/100)*SpreadMultiplier)), math.rad(math.random((-Current_Spread/100)*SpreadMultiplier, (Current_Spread/100)*SpreadMultiplier)), 0)
return workspace:Raycast(RayOrigin, BulletOffset.LookVector*MaxRange, NewRay)
end)
--[[
local Result = Raycast()
]]
As for an explanation on how it works, I don’t know how it does.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.