How to optimize bullets?

I made topic about optimizing large amount of players, thanks to it i found out bullets may be main problem

I used math from this video to cast bullets:

I also saw network latency is huge when creating a lot of raycasts and use unreliable remotes to send bullet’s position and next point it should travel to

Any ideas on how to make those bullets don’t lag?

i dont know but im here to see solutions too

1 Like

I think your looking for server → client replication.

Here is my idea for a flow:
You register the fire & bullet trajectory on the server →
Replicate the bullet shooting on all clients.

This will make sure the bullet fired is moving smoothly as its on the client.

1 Like

I used it but then network overload was 20x larger than it should be, i though on calculating bullets on client but it comes with a lot of security checks and lag compensation issues

I think your networking isn’t on point if its overloading.
security checks are also not neccesary as the trajectory on the server should check for hits.

You should only replicate the bullet (as model) being fired and moving along the trajectory.

1 Like

I did everything to optimize networking, i used unreliable remote events and send only data i needed to replicate bullet, but it didn’t helped reduce bandwidth with 1000 bullets, which is average amount that will be replicated

Uhm yeah with 1000 bullets its obvious it will overload,
what you can try to do is to have a value on the server like local Bullets = 0

When a bullet is fired add +1 to Bullets
and put a cap on how many bullets are shown

so like

if Bullets < 60 then
   -- Replicate the bullet on client
end

with this solution the visual effects are still there but it isn’t overloading big time

2 Likes

Problem is that i can’t simply not replicate some bullets as this may break entire gameplay, imagine player shooting from machine gun with invisible bullets, it would be terrible

EDIT: Also problem is on network itself, not on client side

The problem is that you are sending too much events to the client if your firing 1000 bullets at once

What you can do is checking if the trajectory hits a p.o.i if so just replicate a bullet hitting the person outside of the bullet cap.

So when a user misses the bullets replication is optimized and when a user hits the hit is visual

1 Like

But how do i visualize a bullet? if trajectory is balistic projectile, calculating it both on server and then on client wouldn’t be that performant, right?

Bytenet for client->server->client and PartCache for bullets

1 Like

thx, but i don’t like using open-source modules, as they feel limited to me, can you describe what they do? ik part cache stores instances to be reused, to reduce instance.new, but what byteNet does? some sort of buffering data?

Bytenet transfers buffers using remote events, making it waste like 100x (maybe) less traffic

1 Like

Server

  • Raycast to the point the user wants to fire to (this is the trajectory)
  • Check if the trajectory hits a p.o.i
  • If p.o.i is hit send remote to client
  • If p.o.i not hit check if the max cap is not reached yet
  • max cap not reached yet? then fire remote to client

When firing remote send trajectory end location with it

Client

  • Receive remote fired from server
  • Clone a bullet model and put parent to something in workspace
  • Make the bullet go to the end point of the trajectory by using tween or something like that
1 Like

As i said, this works if trajectory is linear, not balistic parabola, this is why calculating it is very costly each time

Then like the other dude said use the open-source modules as they reduce networking traffic by alot

1 Like

Just so you know, I’d recommend using ObjectCache over PartCache instead.

2 Likes

thx for suggestion, but open-source modules are limited to me and i don’t like to use them, i prefer to seek for other solutions than relying on someone’s else job

Hello,
I recommend sticking to Roblox built-in physics engine. Here is prove it is more performant than changing CFrame.

Here is a video on how to simply achieve projectile physics:

Im not using CFrame, also roblox’s physics aren’t that good for fast moving projectiles

1 Like