Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why do these bullets pause for about 0.1 seconds when shot?

Asked by 5 years ago
local RE  = game.ReplicatedStorage.RemoteEvent

RE.OnServerEvent:Connect(function(p,m,Tool)
        local bullet = game.ReplicatedStorage.Bullet:Clone()
        bullet.Parent = workspace
        bullet.Size = Vector3.new(1,1,1)
        bullet.CFrame = p.Character:FindFirstChild(Tool.Name):FindFirstChild("Handle").CFrame
        bullet.CFrame = CFrame.new(bullet.Position, m)
        bullet.CanCollide = false
        local BV = Instance.new("BodyVelocity",  bullet)
        BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
        BV.Velocity = (m - p.Character.HumanoidRootPart.Position).Unit*600  
end)

--p = player
--m = Mouse.Hit.p
--Tool = The tool.

I shoot with the gun, it goes a bit in the direction it should be, then it stops for around 0.1 seconds, then continues. any way to fix this?

0
uh first the parts with -- are no use... LUCATIVIOMAD 31 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

It's likely a quirk with the roblox engine, i've struggled with it before. You probably can't fix this but there is another alternative that doesn't have this problem, raycasting.

I would just advise you to look more into raycasting if you're trying to create a gun in roblox.

0
I think you might be wrong. Im pretty sure its because hes parenting the body velocities after the bullet is already parented to the workspace. Psudar 882 — 5y
0
I've had the same problem before were the velocity was set before the parent, still didn't work smoothly. Vinceberget 1420 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

This is caused by the Network Ownership system. Every physically-simulated object in the game is automatically assigned a Network Owner that handles the object's physics calculations, and then replicates them to the server/other clients. Even if you instantiate the object on the server, the Network Owner may be automatically set to the nearest client. As the bullet travels further away from the player, the Network Owner changes from the client to the server, again, automatically. Every time a physically-simulated object switches Network Owners, there's a "hop" in the object's physics simulation. This "hop" is the amount of time it takes for the Network Owner to be switched, usually dependent on the latency between the old owner and the new owner.

I would suggest, anywhere in your code after creating the bullet, manually setting the bullet's Network Owner to the server. Manually setting a Network Owner will ensure that it's not automatically changed.

You can do this like so: bullet:SetNetworkOwner(nil)

Passing nil to BasePart:SetNetworkOwner() will set the owner to the server. Otherwise, you can pass a Player object to it and it'll set the Network Owner to that player.

This information comes directly from this article, if you want a more in-depth explanation.

Answer this question