Raycast bullet offsetting when you moving

Hello, I’m making guns and I got one bug. Some reason clientside projectiles offsetting when you moving, there any way how to fix that. (Not my video, but EXACTLY same problem. And I have this offseting little smaller):


My render bullet code(this is local script which placed inside screengui):

local remote = game.ReplicatedStorage.ReplicateBullets

remote.OnClientEvent:Connect(function(character,startPos,direction,range,gravity)
fire(character,startPos,direction,range,gravity)
end)
bulletStorage = Instance.new(“Folder”,workspace)
bulletStorage.Name = “bulletStorage”
function fire(character,startPos,direction,range,gravity)
local lastPos = startPos
local startTime = tick()

    local bullet =  game.ReplicatedStorage.Assets.Bullets.SMG:Clone()
    bullet.Parent = bulletStorage
    
    local blacklist = {character,bulletStorage}
    local rayFilter = RaycastParams.new()
    rayFilter.FilterType = Enum.RaycastFilterType.Blacklist

    for _,char in pairs(workspace:GetChildren()) do
            if char:FindFirstChildOfClass("Humanoid") then
                    for _,accessory in pairs(char:GetChildren()) do
                            if accessory:IsA("Accessory") then
                                    table.insert(blacklist,accessory.Handle)
                            end
                    end
            end
    end

    rayFilter.FilterDescendantsInstances = blacklist
    
    while range > 0 do
            local timeLength = (tick()-startTime)

            local currentPos = startPos + (direction*timeLength)
            local distance = (lastPos-currentPos).Magnitude
            range -= distance

            local ray = workspace:Raycast(lastPos,currentPos-lastPos,rayFilter)
            if ray == nil then
                    ray = workspace:Raycast(currentPos,lastPos-currentPos,rayFilter)
            end
            if ray then
                    local hit = ray.Instance
                    currentPos = ray.Position
            end
            
            local bulletOffset = CFrame.new(0, 0, -(lastPos-currentPos).magnitude/2)
            bullet.CFrame = CFrame.new(currentPos,lastPos)*bulletOffset
            bullet.Size = Vector3.new(.1,.1,(lastPos-currentPos).magnitude)
            
            if ray then
                    break
            end
            lastPos = currentPos
            local t = tick()
            repeat task.wait() until tick()-t >= 1/60
    end
    local t = tick()
    repeat task.wait() until tick()-t >= 1/60
    bullet:Destroy()

we can assume there is probably some sort of delay right? perhaps its this line? why do you need this?

Index the startPos in the script instead of getting it from the server. This should make it look the way you desire.

1 Like

Compability with fps unlocker (bullets looking spaced when it’s more that 60 fps), removing it not fixing problem.

I can’t I guess, because it’s other script which replicates bullet at screen gui for all players, I just can 't get firepoint post.

startPos is the barrel right? Replace it with the gun instance instead and do

startPos = gun.Barrel.Position -- index to barrel or whatever you want it to be

as your start position instead.

Now bullet not offseting. But now it not sync with ray


.

make the bullets on the client, then have the server process the damage

It’s already -_-

Character limit skill issue