Download

Multiplayer projectile velocity inheritance

I’m currently working on a 3rd person shooter game with multiplayer in space. Since there is no air resistance, characters and spaceships are allowed to accelerate to very high velocities, which has created a problem I’ve yet to solve: When flying around, the projectiles collide with the player as soon as they’re spawned.

I’ve read up on many threads on the forums and the internet in general on how projectiles are handled in a multiplayer scenario, from pooling to spawning non-replicated bullets on every machine. My initial setup was to spawn to spawn replicated projectile actors, which had their velocity immediately set to inherit the players velocity + their own velocity. Unfortunately, the replicated projectiles didnt seem to spawn the effects reliably on the clients, so i switched to spawning non-replicated bullets on each machine to exclusively handle FX and a dedicated bullet to handle damage on the server. The necessary spawn transform and velocity was multicasted to the clients to ensure all bullets are in sync.

This worked fine up until a certain velocity where it seems that the execution speed of that logic is not fast enough and the player collides with the projectiles before the velocity is set. That’s where I tried implementing pooling my clip, by spawning the whole clip at BeginPlay and attaching them to the muzzle of the gun and just setting the velocity + detaching them when fired (collision and visibility was handled the same way, toggled when fired). That however caused a huge fps drop, so that didnt work out either. I reduced the clip size to 5 bullets, if at least the bullets dont collide with the player anymore, since they dont have be spawned anymore. Unfortunately, they still collided with the player.

My current setup is a hybrid of spawning and pooling, where I just pool a small number of projectiles, that destroy themselfs after usage and are replaced in the pooling array after they’ve been fired, similar to how a gatling gun works.

I have no idea about how to further optimize the process of setting the velocity before the projectiles collide with the player (I was secretly hoping to find a way to set the velocity before spawning the projectile, but to no avail), any adivce is greatly appreciated!