I’ve been searching for a way how to fix this all day, i’m going to try my best to explain what is going on.
So I’ve made a gun that shoots a bullet, it works fine when shooting at the sky + when shooting at a part. I decided to give the bullets a spread so they don’t go right to your mouse.
The bullet spread works perfectly fine when shooting at a part but when shooting at the sky it has offset issues, the bullet trace doesn’t connect to the gun and starts going all over the place.
Here is my code: ```
local ray = Ray.new(gun.Point.CFrame.p, (mouse.Hit.p - gun.Point.CFrame.p).unit * 600) local part, position = game.Workspace:FindPartOnRay(ray, player.Character, false, true) local beam = Instance.new("Part", workspace) beam.BrickColor = BrickColor.new("Bright yellow") beam.FormFactor = "Custom" beam.Material = "Neon" beam.Transparency = 0 beam.Anchored = true beam.Locked = true beam.CanCollide = false local distance = (gun.Point.CFrame.p - position).magnitude beam.Size = Vector3.new(0.1, 0.1, distance) local Spread = 1.25 local Direction = (CFrame.new(gun.Point.CFrame.p,mouse.Hit.p) * CFrame.new(0, 0, -distance / 2) * CFrame.Angles(math.rad(-Spread+(math.random()*(Spread*2))),math.rad(-Spread+(math.random()*(Spread*2))),0)) beam.CFrame = Direction game:GetService("Debris"):AddItem(beam, 0.1)```
gif of what im talking about:
Thanks in advance to anybody who helps me