How to tell if a client should render a projectile

I am making an fps game and have seen thing saying that I should only render a projectile if the client can see it and is close enough to it.

Here was the thing I was reading:

I have done everything so far except for the other clients part.

Can someone give me a code example of how to do this?

Thank you!

1 Like

I agree with most of that post, but disagree that clients need to check whether to render a projectile or not. There’s overhead involved with that, both development-wise and execution-wise. You also run the risk of introducing more bugs as you make the code more complex.

That’s the kind of optimization that you should only add if:

  • you profile your game and see that creating and rendering projectiles is really a cause of lag, and
  • it really does end up faster to do the distance and viewport checking before instantiating the part.

Also, realize that “rendering” the parts isn’t the problem. ROBLOX is almost definitely already doing things like viewport and visibility-culling in the background to prevent rendering parts that you can’t see. They’re probably better and faster at it than you are (not a diss, they just have access to backend code that you don’t). The “slow” part (if it’s actually slow) would be instantiating the objects that represent the projectiles.

1 Like