What is the best practice for projectiles

What would be the best way to

  1. move magic projectiles think fireballs and rocks

  2. what would be the best way to code the hitbox for them

keep in mind I am not a new scripter I am just conflicted on which methods are best for actual games

1 Like

Projectiles movement and effects should be handled on the client (FireAllClients), as it will look more smooth.

Damage, sanity checks and some more stuff should be handled on server.

(Keep in mind this is the way I do it, that doesn’t mean it’s how it should be done.)

2 Likes
  1. Make a function in the client that handles projectile movements. If a projectile is launched, in the server, use RemoteEvent:FireAllClients, then send arguments such as (projectile:Model, direction:Vector3,blahblah). You will also do in the server, for the sake of hitbox

  2. Hitbox detections are done in the server. Small and fast projectiles, like arrows, pebbles or bullets, you need to use raycast. Raycast from the old pos to the current pos. If the projectile is pretty big, lets say a fireball, you can raycast on two corners opposite from each other. For big projectiles, you can use workspace:GetPartsInPart.
    There are also some modules you can use for hitbox detection, like this
    Raycast Hitbox 4.01: For all your melee needs!

4 Likes

Hey! I would like to know why moving the projectile in the client is better… If I’m not wrong, everything that is on the client (moved, added, etc) doesn’t replicates in the server, therefore, others players wouldn’t be able to see that projectile moving, right?

I want to know if I am right, thank you!

Although the server won’t see the movement if you do – RemoteEvent:FireAllClients()
Every client in the game will be able to see the projectile moving

1 Like

The reason you do most effects/movements in the client is because of latency. Remember that lag is a thing, anything that changes in the server, takes time to replicate

You are right, but I also said

.

1 Like

Oh, I see now. Thank you so much!
You too @Lielmaster!

Isnt FireAllClients a lot heavier on performance than doing the movement on a server script? You are making lags seamless for one person who has bad inet, at the expense of experience of others with normal inet

1 Like

Tbh with you, never felt any problems using FireAllClients.

Moving projectiles on the server makes the projectile movement look very weird and laggy

FastCache and PartCache are a great combination for handling weapon projectiles and effects.

thats how i do it also
(word limit)

do you use body velocity or tweening or cframe to move the fire ball

I personally would use raycasts for this.

On the client it goes like so:
-Spawn projectile model.
-Do tiny raycast forward.
-Hit nothing? Good, move projectile to that location.
-Wait 1 frame/heart beat then repeat.

Fire a remote to all other clients to spawn the projectile as well (but with a small offset because of lag).

-Using this raycast method also makes bullet drop relatively easy as all you have to do is add a small angle to the raycast to make it go more towards the ground.

-You can despawn the projectile if it has done more than 200 raycasts for example to limit the total distance it can travel.

-Doing larger raycasts only every 2 frames instead of small ones every single frame can help optimizing/making this even faster in games that have thousands of projectiles.
The only thing you’re sacrificing here is that if you have bullet drop then it’s arc will make sharper turns and look less smooth but this won’t be noticeable if it moves fast.

2 Likes

I use RunService.Stepped to move the projectile, then on the server, do raycasts

1 Like

actually it’s how it should be done usually that is the best solution, anything other than that might be more complicated and unneeded

1 Like