How to make INSANELY smooth grenades

Create the grenade with the same parameters on the client first
Then send the remote event to create the REAL damaging grenade. Replicate this as you will, fire all clients except the client that sent the remote event to replicate the grenade
if the REAL damaging grenade hits something do the explosion damage, fire client, destroy the fake grenade, and do the explosion visuals

-- Client sided
local Grenade = "Basic"

local function OnGrenadeActivated()
    GrenadeModule:VisualThrow(Grenade, power, angle) -- only visuals, idk if u should make this OOP
    GrenadeActivated:FireServer(power, angle)
end

-- Server Sided

local function OnServerEvent(plr, power, angle)
    --probably make this some sort of OOP?
   local Grenade = GrenadeModule.New()

   grenade.Type = plr.EquippedGrenadeType -- don't send any data about the grenades type to the server. 
   --Acquire the type of grenade yourself with a string or something that the server has control over
   grenade.Power = power
   grenade.Height = angle
    --You'd wanna check clamp the power and height variables to prevent exploiters
   Grenade:DamageThrow() -- only damage!! although the Type property should contain the model too, for client-replication ofc
    
    for i, v in Players:GetPlayers do
        if v == plr then continue end
        ReplicateGrenadeThrow:FireClient(v, grenade:GetProperties())
    end

    Grenade.Exploded:Connect(function(grenade) -- use a signal system like goodsignal for this
        ReplicateGrenadeExplosion:FireAllClients(grenade:GetProperties())
    end
end


-- client again

local function ExplodedGrenade(properties)
    -- create a visual for the explosion, destroy grenade on client, track these grenades with IDS or something
end

local function ReplicatedGrenade(properties)
    GrenadeModule:VisualThrow(properties.Type, properties.Power, properties.Angle)
end

Another suggestion you could do to optimize networking and improve responsiveness is to handle the visual destroying of the grenade completely on the client and to track these grenades use OOP. Maybe this would require it being OOP so you could track the grenade object without server-provided IDS, and if the client’s simulation bugs out the grenade wouldn’t explode where it should, so you’d probably still have to use a sort of ID system to destroy it if it already isn’t destroyed on the client (Incase of the simulation bugging out)

1 Like

I recommend syncing moving objects like sliding walls with ping so your game doesn’t have any issues with client-server correctness, I think suphi kaner has a video on this about animation synchronization

In that case no one else sees the grenade, it’s far better to just do it on the server side and set network ownership to the thrower so all the client will be doing all the physics handling ultimately making it smoother

1 Like

I think using fastcast negates this issue anyways, since raycasts aren’t as computationally expensive nor as frequent as physics calculations
You can have custom fastcast lengthchanged functions to apply erratic impulses at random too

1 Like

I would personally just let roblox physics handle it after I apply initial impulse but most of the responses here are exactly what the op should do.

p.s I’ve never touched fastcast so I can’t make a comment about that.

1 Like

image
I @-ed you, lol

1 Like

Thank you guys for all the answers! Keeping the grenade and physics on client make it 10x smoother.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.