Best Approach to Timing Projectile Impact and Damage?

My current projectile system right now is pretty basic:
User presses a key —> A projectile is cloned on the client and begins to Tween towards the enemy —> The Server decreases the enemy health and tell all other clients to replicate the projectile. When the projectile tween completes, the hit effect is played and the enemy does his animation. There is also an autotarget feature so there is need to check if the projectile actually hits.

Before, I had no issues with my system since the delay between the client and server was enough so that the enemy’s health decreases roughly around the same time the projectile reaches the enemy. I’m also not too concern with having projectile and damage match up on other clients as I am with matching them up on the client of the player who actually fired the projectile.

But I’m trying to expand my system to include more complex abilities where one ability have multiple projectiles with a short delay between each other(eg. Meteor Shower). With something like this, I want the enemy to take damage upon each projectile and for it to happen the moment the projectile touches the enemy.

I’m struggling to think of a way to do this effectively. If I fired the remote when my tween completes that would solve my problem except there would be huge delay in replicating projectile on other clients. Another way might to just use task.wait() but task.wait() is incredibly unreliable. The best approach I could think of is to fire a remote when the button is pressed to replicate the projectile and another remote when the projectile tween completes. But I’m don’t exactly find myself exactly liking the idea of firing two remotes for one action so I’m asking for inputs on how to best approach this and if I’m being too conservative with my use of remote events.

Thanks and I apologize for any rambling, it’s really late for me and I am not the most articulate right now.

1 Like

The player using the ability should relay all information relating to this projectile to the server, which should send the information needed to create this projectile visually to all clients in the game.

If you want to have a projectile that detects for objects, you should look into raycasting. If you’re looking to do damage as it travels, you could break the path of the projectile into segments of raycasts, and for each segment, you can check for any characters within range. If any characters are found, you can do the necessary damage.

An example:
A player shoots a fireball. That information gets sent to the server. The server does all the necessary calculations to fire that projectile to its destination, and then can raycast towards that direction and tell all the clients to replicate the visual effects of the projectile. Upon impact, you can do damage on the server, and replicate another set of visual effects for the impact explosion to the clients once more. If you don’t plan on raycasting, the same result can also be achieved.

Firing a remote twice for one ability is no problem, I wouldn’t worry about that. Everything can get a bit complicated to explain since there’s so many parts to it, but you should try practicing and improving upon your system.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.