Hello, I am making a game with projectiles in them, and I want to know the best way to code it.
I used to put it all on the server’s side using default roblox physics (like body velocity), but it turns out that the server side is very bad at handling physics.
After examining how other games do it (BIG Paintball, Arsenal, Bedwars, Jailbreak, etc.), I realized that their projectiles are run on the client side. (The way I figured this out was when I get disconnected from the server without a message, where the server side froze but the client side it still running, and I could still launch projectiles perfectly).
This method has good performance but allows exploitations to occur as the client controls the movement of the projectile. So I’ve decided not to use this method
The other two methods I have thought of is
Let the server manage the projectiles, using CFrame and loops to move the projectile
This one is very complicated, basically the server tells all the client the start and end point of the projectile, the client move the projectile, but the effect of it (e.g. when it hits something, dealing damage to players who got hit) are still handled on the server through math operations.
Is there a better way to do this? I haven’t made up my mind about it yet, and want to hear more about your ideas . Thanks for reading and please reply if you have an idea.
You could create a new projectile and get it to move through `cFrame’, it does not require the use of Roblox physics and is what I will do in this case. And if you want to make the projectile visible to other players, make sure that the code is in a server-sided script.
People would have Projectiles Run on the Client because its more performant, puts less strain on the Server, and more smoother than on the Server, there are a couple of games that do this on the Server, but that more of involves the Usage of Network Ownership which would help with controlling Physics of Objects, Along with Body Movers which are now Deprecated.
CFrame Is another option as well, Along with Lerping the Projectile!
Plus, if you want something like Bullet Tracers, or Actual Moving Projectiles, Run them through a RemoteEvent and Fire to All Clients, so this would fire for the Players that are in the Game on theri Clients and not on the Server.
You Handle all the Important bits like Raycasting on the Server.
Hi, I want to run it on the client but I don’t know how to calculate if the projectile touched another player through the script, since the part only exists in client side. How would I handle raycasting on the server to see if the projectile touched another part / player?
I’m not very good at making projectiles but this is my simple script. It’s pretty smooth too at lower traveling increments. (Like 0.5-2 studs per frame is good.)
I modified it a little and now it works really well
local moving = true
while moving do
projectile.CFrame += projectile.CFrame.LookVector*2
if workspace:GetPartsInPart(projectile) then
projectile:Destroy()
moving = false
--additional effects, damage, etc.
end
end