How do you make a completely local projectile?

Hey everyone,

I need help figuring out how to make the following:

What I want to make is essentially a giant wall of “guns” that spawn in front of the player and point to where the player’s mouse is. For obvious reasons, these guns have to be local as to prevent lag, especially since they quite literally spawn out of thin air. (Only 1 gets spawned server side, rest is duplicated locally on each client)

Now I would like for each of these individual guns to fire at random and be able to actually miss the target. The guns use actual projectiles. If you need a better idea of what I’m trying to make, just imagine the attack from this gif, coming from many different angles.

I had the idea of shooting rays at the mouse from an attachment whenever something hits, but that’s a pretty poor solution because everything would land if the player’s mouse tracked the enemy perfectly. All it would do is prevent hackers from shooting through walls. It would still give them perfect aim.
So, how do I do this properly?

What why completely local projectile if you think all on clients side easily don’t do it because hackers can use exploits to execute local scripts

I recommend having a bullet visualizer for other clients who shoot, do all the raycasting and bullet creation inside the weapon, and then the bullet visualization happens when the other client invokes/fires the server and it fires all clients, and plays the sound in their weapon. Basically try doing a hybrid server/client.

1 Like

And its more anti hacker because i cant edit projectiles by exploits

Hm but like I said a raycast ain’t gonna work since the projectiles being shot and hitting the player have considerable delay. If I shoot the raycast out right at the start it’ll hit the player no matter what even if they didn’t hit in the client and if I do it when it impacts on the client hackers can freely say where the projectile landed.

And it’s not like I can even create a raycast for each gun since the amount of computing involving creating so many rays would easily slow the server to an absolute crawl. Unless you meant something else, anyways.

edit: And if I base wether it hits or not to be on the receiving client 1. hackers can easily just destroy the projectiles in mid air and 2. it won’t damage NPCs.

If you’re making a completely local projectile, it would be exploitable. In my opinion you should create one real turret on the server, and have all of the others clone from Replicated Storage by the client. The fake ones shouldn’t do any damage or anything. This way it shouldn’t effect the server.

Edit: I completely misread your post. Sorry about that.

Many systems use sequential rays, synchronized with a velocity-based projectile. I.e, you have a projectile that travels 10 studs per second. You care about checking collisions every 0.25 seconds. So every 0.25 seconds, your bullet will traverse 2.5 studs (v=d/t; v=10, t=0.25, solve for d to get 2.5 studs). First shot, a ray starts at the barrel, and travels 2.5 studs, checking for collisions. If it hit nothing, wait 0.25 seconds, then create another ray, starting from the end of the last ray, going forward another 2.5 studs. Continue this process until it’s traveled too far, or you’ve hit something. I would do this on the server, though I can see an argument for client as well.

Meanwhile, you have the velocity. Just use a body force on a part and move it at that velocity in the same direction. There will be some minor staggering, but the two should line up closely. I would do this on the client, but again, I can see an argument for server side.

It would work well for a single shot projectile but it might lag if 15 of them get shot per second per player…

That’d be an argument to perform those intensive calculations on the client. So long as you do proper checking on the server in the end. 10 clients each calculating 20 shots times per second is better than the server calculating 200 bullet traces per second.

I’d need to do a sanity check for every single one of those projectiles though which would still lag the server like crazy.