x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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: alt text

Product Version: UE 4.21
Tags:
weaponbp.png (339.5 kB)
more ▼

asked Apr 12 '19 at 09:50 AM in Blueprint Scripting

avatar image

Wiresharkk
8 1 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Apr 12 '19 at 06:20 PM

avatar image

Deconstructor
71 3 2

avatar image Wiresharkk Apr 13 '19 at 08:49 AM

Thank you so much for your answer, it's very helpful. One problem tho is the fact that we are making use of a listen server, and the error between the server and the client is not neglible due to its dimension. (we're talking like up to 90 degrees error) Another thing that I have noticed is the fact that if the server pawn directly sees the client, everything works just fine. On the other hand, if the server pawn doesn's see the client character, then the pitch stops getting replicated, and big offset is introduced in both the yaw and the actor location. Anyway if i get it right, as you said we should fire the projectile from the server, but from the location dictated by the client. We'll try to do that, but is the replication problem that we're having normal? Thank you again so much!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question