Download

Projectile fire behaves differently in client then in server

Hello everyone! I have been having a problem with how my projectile behaves in client compared to in server. when a projectile is fired from my character it looks as if the spawn locations for the projectiles are different. here is an image of the moment the projectile is spawned for both the client and the server.

Shot Location problem.jpg

As you can see the location of the projectile is significantly further away from the character in the client than it is in the server which is actually causing a big problem during gameplay. I’ve tried everything I can think of, but I haven’t been able to solve this problem.

Here is the part of the blueprint for my weapon_template class, which handles all of the projectile spawning.

ce8daec9b5fa8c01876be9b057012db171a45f8d.jpeg

‘Spawn Distance From Weapon’ Defaults at 40 and is never altered.

If you have any ideas how to fix this problem please let me know! I really could use the help!

follow up question, could it be that maybe the projectiles are spawning at the same location, but for some reason the client projectile isn’t rendering correctly?

shameful bump… Really could use some help if anyone knows what my be causing this problem

Did you zero out the velocity for your tests? Have you tried just spawning the projectile on the server (it definitely should replicate at the same location for all clients if spawned on the server)?

I have tried that, but honestly I cant remember the results. Ill try it again and post an image as soon as I can.

I see your event to spawn a project is called “Fire Projectile Multicast”. Is it a multicast event? I don’t think it should be, spawning stuff is usually the task of the server only. Multicast would cause the server plus all connected clients to try and spawn a separate projectile. Can this be related to your problem?

Also, isn’t the client just seeing the projectile after it has already traveled a bit?

When I ran on server it would only spawn a projectile on the server screen. Im just getting home from work, let me try really quick and ill try again.

OK turns out it still works on run on server, but that doesn’t fix the problem.

I zeroed out the velocities and it looked like they were spawning in the same spot. I kept increasing the velocity, but the higher the velocity the larger the difference in the location that it looked like it spawn. I decided to print out the projectile’s location from the server and the client. and this was the result.

The Locations were exactly the same yet in the image you can tell a difference. that makes me think the projectile is rendering late on the client screen.

So i’m a bit baffled.

If it has velocity, the location will always be different for every client/server. Replication takes time. Until it spawned on the Client, it will have already traveled some distance on the Server, the greater the speed, the further it will travel until replication is finished. You’ll never have the exact same things happen at the exact same time for anybody.

So is there anything I can do to make it seem as if it is happening at the same time?
It is very noticeable in gameplay.

EDIT: Was doing some more testing and realized another thing. I have a particle effect that happens when a projectile hits an object. In the client, when a projectile hits something at a distance closer than the first time you see the projectile, then it will not do the effect.

There are ways to optimize/interpolate/predict things, however they are rather complex and probably not something one would do with blueprints on beginner level. Writing a Tutorial for this is beyond my scope.

However I think for firing your gun you shouldn’t really have the need to spend many resources on something that works quite OK the way it is. The Gameplay issues you have are probably related because you don’t create the projectile on the server only. Just create it on the server and you should be fine (generally important gamelogic should always be calculated on the server #desync #cheating).

Let’s assume you have a delay of 100 ms, when you spawn the projectile on the server, the client projectile will be 100ms behind. And when the Server registers a hit, it will again be about 100ms until this message is sent to the Client - so in generally it does “seem” to be happening the same time.

Regarding your particle effect, this is probably again related to how you handle things. Calculating the important game logic on the server and multicasting visual effects like your particles should fix this aswell.

So as far as seeing the bullet slightly later than I would like, there is not much I can do about it. But I can still handle the game logic on the server. am i correct?

ok and i changed my particle effect to multicast and it still does not play on client side.

Generally yes, handling the important logic on the server should fix your gameplay problems.

About the replication delay, it’s not that bad after all - as I tried to explain above, the whole game has this delay.
The light of the sun takes approximately 8 minutes to replicate from the sun to the earth. Do you ever notice the delay? Our nerves ain’t transfer data instantly either, we all live in the past.

Though game networking is of course a little different and you have variables like the Players ping etc. You may want to read up how the different AAA titles handle delay compensation. Unfortunately I don’t have any Epic related articles to link, so I’d just suggest to search the web for it.

Ok I fixed my multicast problem. I was accidentally spawning the emitter after the actor was destroyed which was useless. so thanks to everyone that helped. You guys rock!