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()