Actor Location not replicated properly
Hello, I have a big problem with the replication of a projectile. In my current setup, the server spawn the projectile at the location retrieved from get world transform of the arrow component attached to my weapon. When the client and the server are very close to eachother, everything works as intended, but if I move the client away from the server (I don't think it's a relevancy problem because we're talking like 15 footsteps) the projectile is fired in a coompletely wrong direction. I have noticed that the client has the correct location of the arrow component, while the server doesn't. Is there a way to fix this? Note: The actor is replicated, I have also tried "Replicate Movement" but it didn't work. Thank you!
This is the Weapon Blueprint:
asked Apr 12 '19 at 09:50 AM in Blueprint Scripting
Generally speaking for weapons in a multiplayer game, you don't want to assume that the server's state is completely up to date like that. While it's true that for the most part "never trust the client" is the rule, the vast majority of multiplayer games out there make some compromises on this for game-feel/fairness reasons.
In a networked game, especially over the internet, your guarantees that the server state will be anything close to a fair representation of your client state are somewhat limited. (For many reasons, latency being one, the frequency with which the data is sent being another, and also how accurately the server can possibly reconstruct that data based on what you actually sent). This is especially true for aim transforms, which are typically going to be very noisy data that changes unpredictably from frame to frame (especially if players are aiming with a mouse).
Typically when informing the server/host that a client fired a weapon, most games will send some information along with that RPC to allow the server to create some kind of fair reconstruction of what happened on the client. Obviously you have to be careful about cheating here, but it's pretty common to send out information like "this is the entity that was hit by the player's reticle raycast that frame, and this is how offset the player's aim transform was from some known point on that entity, such as a bone or the root. If that raycast didn't hit an entity, then we were aiming for some point calculated based on the muzzle transform and the max effective weapon range". Then you could have your projectile fire towards that point on the server.
Alternatively you could send the actual muzzle transform from the client, and the server could either fire directly from that transform (which could look bad if the client/server states have diverged a lot, and possibly be open to cheating unless you put some sanity checks on it), or we could use that to figure out where the client was aiming (e.g. MuzzlePosition + MuzzleRotation.ToVector().Normalize() * WeaponMaxRange), and then have the server aim at the same point.
Basically it's all a big compromise between making the game feel good and fair on the client, making it hard for people with hacked clients to cheat, and making the game feel fair to other players.
answered Apr 12 '19 at 06:20 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here