How to make unanchored physics objects less laggy

So, in my game there is a load of unanchored objects around the map, being chairs, boxes, crates, etc. You can pick them up and throw them, and the enemies can kick them around.

But they lag the game a load, as there is like 200 around the map. How could I optimize this and prevent lag?

What I would do is, on client, loop through each object and gather all that are within a radius. Then, send a RemoteEvent to the server determining which objects are in that radius and unanchor them. If they’re not in the radius, anchor them.

2 Likes

what type of lag are you seeing? legitimate lag where you can barely move your camera, or does it seem like the physics take a while to respond?

if it’s legitimate lag, set the network ownership of all of the parts to your player if the game is singleplayer. otherwise, set the network ownership to the client of the player the moment the pick the object up. a few seconds after they throw, set the network ownership back to the server. you might want the server to double check where the parts are going

1 Like

Why would you do that on the client? Wouldn’t it be better to just loop through them on the server?

fps, people on lower end devices are saying its laggy and low fps. The game is decently well optimized, so this is the only thing I can think would be an obvious issue

you can unload them when far away, or just anchor them when not in use for a while

You’d do it on client so you don’t have to waste server performance looping through each object for each player.

1 Like

It wouldn’t really be enough loops to cause any real amount of performance. assuming 20 players, and 200 objects, its just 4K loops. you don’t need to loop more than once per 3 seconds too.

and you’re telling me 4k loops isn’t a lot?

Not if spread out over 3 seconds.

it’s not “spread out” over 3 seconds, it’s done every 3 seconds. big difference.

There is a big difference. Instead of doing it all at once, doing it over 3 seconds is significantly better.

Quite the backpedaling:

if you meant SPREAD OUT over 3 seconds, should’ve made that clearer to begin with

1 Like