Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to replicate projectiles properly?

Asked by
trecept 367 Moderation Voter
5 years ago
Edited 5 years ago

I'm creating a laser gun that will make small neon parts that act as the projectile laser. I'm not sure how I'd make the projectile move a projectile and if it's better to replicate the actual movement on the client than the server, and when to show it's hit something. What's the best way to do a projectile, fully serverside or on the client? And best way to move it? (e.g bodymovers or tweenservice)

EDIT: Is it better to use network ownership or create the actual projectile on the client?

1 answer

Log in to vote
2
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
5 years ago

There are two ways that I know which you can use in order to do this:

1) Creating the projectile on the server and using network ownership to move it

In order to do that using this way, you would create the projectile on the server, set its ownership to the player and let the player's localscript handle moving it.

I personally don't have any experience with it, but I believe this way would only be good for slow projectiles such as rocket launchers, due to the delay in communicating between the server and the client.

And that's not the only issue with it. As you can read on this page, you cannot apply network ownership to anchored parts, meaning your bullet would have to be unanchored, therefor forcing you to use BodyMovers, which may not always be preferred.

2) Creating the projectile on every client separately

This way let's you anchor the projectile, and move it by setting its CFrame, without the need to use BodyMovers. In order to do this, you would have the server tell every client to create the projectile here and there, moving this way or that way.

This way is probably better for fast bullets. I know for a fact that Jailbreak uses this way in their weapons system.

TL;DR in my opinion, it's better to create the projectile on the client, especially for fast guns.

0
What would be the best way to set it's CFrame, tweenservice or lerping or? (If I wanted an anchored projectile to move forwards at a constant speed until it hits something) trecept 367 — 5y
0
If you use TweenService, you will have to calculate the "time" parameter of it. Otherwise the bullet would take the same amount of time to move over different distances, which means it would move very slowly on short distances, and very fast on large ones. Now, if you use a for loop without lerping, you can simply abort it after the bullet hits something or reaches the end of a ray. Amiaa16 3227 — 5y
0
If you do use lerping however, you will have a similar issue like with the TweenService. Amiaa16 3227 — 5y
0
Ah ok. One more question, if I am going to create a projectile on all clients, should I also make an invisible one on the server so I can see where it hits? trecept 367 — 5y
View all comments (3 more)
0
You don't have to. If your projectile is a fast one, like the ones on Jailbreak, you can just fire the RemoteEvent with the Ray, and have the server script check if the projectile hits a player (using the ray), and if it does, deal the damage to said player (and obv tell all clients to create the projectile). Amiaa16 3227 — 5y
0
My projectiles will be relatively slow compared to fast shooting ones in other games, so I want the effect to only begin once it's actually hit instead of instant raycasting, would making the actual projectile or calculating the distance and applying effects after a certain time be best? trecept 367 — 5y
0
Just realised if I calculate the distance and wait that'd be silly since if it was aiming at a player they would've moved. I don't want to strain the server with calculating projectiles itself though trecept 367 — 5y
Ad

Answer this question