Announcement

Collapse
No announcement yet.

Networked "Physics-Vehicle Movement Component": existing examples or implementation hints?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • replied
    Originally posted by TheJamsh View Post
    Did this already for my Hovertank Movement Component:
    The server then processes the movement on the craft from the same Input, and sends it back via the 'ReplicatedInput' struct. When this struct is received on the client, they update their local un-replicated copy of the struct, so that their input level matches that on the Server at that time. Additionally, the ReplicatedMovement from the Server (since it also processed the input) is sent back with it, and the position is updated on the client from that automatically.
    Very cool. Do you then replay the client's inputs since the client move that was executed on the server and received by the owning client again (in the case of a disagreement)? If so, what does the replay look like? Are you ticking the component outside of the owning actor's `Tick()`, or just reapplying deltas?

    Originally posted by TheJamsh View Post
    Did this already for my Hovertank Movement Component:
    There are two caveats to this approach at the moment. The first is that unless the Server is sending back Replicated Movement constantly (I.e, calculating it) - there's the potential for a Client-Side collision to knock the two out-of-sync. I don't think this is an issue really, since I'm fairly certain that this is what the CharacterMovementComponent does anyway.

    The other issue (that is caused by the one above), which only became apparent in high-latency situations - is that the clients input gets simulated, but it gets overridden by the 'Replicated Movement'. Effectively what happens is the Client waits for the Server to simulate the movement and then moves accordingly. If I can get some finer control over the order of operations here, I can work around this though. For LAN play, the controller latency is practically nothing anyway.
    Character movement uses clientside prediction + rewind/replay, so the server lets the owning client know when it disagrees with the results of a move so the client can rewind back to the move in question, correct it, and replay all the clientside moves since then. If the moves aren't replayed, you'll notice the client's simulation snapping back to the last one received from the server, which is of course movement from the past as far as the client is concerned.

    I noticed with the wheeled vehicles that the controls start to get a bit floaty as soon as some normal latency is involved. I'm planning to give the client control, but I'll have to sort out replaying physics states and acking timestamps between client and server (might be pestering you about that soon, @HateDread).

    Leave a comment:


  • replied
    Did this already for my Hovertank Movement Component:



    The system is really simple, what I do is first check 'Replicated Movement', which will first ensure that both vehicles remain in-sync with one another from Server-Side Movement. What I then do is create a Struct which has all of my input states. I later plan on quantizing these for optimization, since in reality I only care about the first decimal point in terms of granularity:

    Code:
    float ThrustInput;
    float StrafeInput;
    float SteerInput;
    float PitchValue;
    bool bIsJumping;
    I create two variables of that struct in the class, ONE is replicated and the other isn't. The non-replicated struct is used in the movement component to actually move the craft and perform all calculations, and ultimately is what updates the physics of the craft. That Struct is ALSO the one that is updated via the keyboard/input component - so clients simulate their own movement locally and instantly.

    I then send this movement data, on-tick, via an unreliable RPC to the server. This is the unfortunate downside as it requires me to send the RPC on tick, though for now it's fine since I'm only doing this for one vehicle per-client and therefore the overhead is pretty small. As it's also unreliable, the engine can choose when to send and not send packets depending on bandwidth. I might be able to get away with sending this on a Timer in future to reduce the amount of sends too, since Tick isn't always going to have the same Delta time, and therefore bandwidth usage will fluctuate up and down depending on framerate.

    The server then processes the movement on the craft from the same Input, and sends it back via the 'ReplicatedInput' struct. When this struct is received on the client, they update their local un-replicated copy of the struct, so that their input level matches that on the Server at that time. Additionally, the ReplicatedMovement from the Server (since it also processed the input) is sent back with it, and the position is updated on the client from that automatically.

    ---

    There are two caveats to this approach at the moment. The first is that unless the Server is sending back Replicated Movement constantly (I.e, calculating it) - there's the potential for a Client-Side collision to knock the two out-of-sync. I don't think this is an issue really, since I'm fairly certain that this is what the CharacterMovementComponent does anyway.

    The other issue (that is caused by the one above), which only became apparent in high-latency situations - is that the clients input gets simulated, but it gets overridden by the 'Replicated Movement'. Effectively what happens is the Client waits for the Server to simulate the movement and then moves accordingly. If I can get some finer control over the order of operations here, I can work around this though. For LAN play, the controller latency is practically nothing anyway.

    ---

    EDIT: I also forgot, I haven't yet got my implementation working with AI / pathfinding, since it's based on Input from the keyboard, and the current AI system in engine quite literally just 'set's the velocity of an object. That's fine, if you're working with characters. For anything else it pretty much sucks. I'll have to write my own interface between the two eventually, which talks directly to the input of the craft rather than essentially hacking it.

    Leave a comment:


  • replied
    Thanks for the mentions, piincone

    I actually didn't get too deep into this stuff; we ended up switching to LAN-only, and I basically implemented Valve's buffer interpolation method, however to do so you need a nice synchronized timestamp system that works regardless of ping, so if you have trouble with that just let me know!

    I'm also happy to answer anything that I can. This stuff is tough at times, and I'm not envious of you guys trying to get wheeled vehicles to work! So, good luck

    Leave a comment:


  • replied
    Just a quick update. I didn't have time last weekend to get into attempting to predict and correct vehicle movement, but I did do an experimental physics projectile implementation. It went well, but I still prefer blending the client's simulation with the server's and snapping velocity in most cases. However, it occurred to me (because I think I saw HateDread float this idea somewhere) that instead of replaying position and velocity deltas for a projectile, I could `Tick` the scene component. Perhaps that would be a better replay than what I implemented, which was very simplified and would often discard the move queue to avoid a feedback cycle after a correction. Ticking the component feels like the equivalent of replaying the move for actors that move as a result of input.

    I started digging into the vehicle code but didn't have time to try anything interesting.

    Leave a comment:


  • replied
    Originally posted by elfprince13 View Post
    Thanks for the response, and please let me know how your experiments go this week. I'll be sure to post updates as well if I find anything particularly interesting in CMC.
    Cool. I will do that, and I'll publicize the relevant code if it goes well.

    Leave a comment:


  • replied
    I'll be honest: I was really hoping to avoid implementing the whole Fiedler dance-routine myself from scratch, but I'm glad my basic analysis of the situation was pretty much correct.

    I'll probably be needing AI players at some point, but I guess RVO isn't a priority out of the gate.

    Thanks for the response, and please let me know how your experiments go this week. I'll be sure to post updates as well if I find anything particularly interesting in CMC.

    Leave a comment:


  • replied
    I was about to come in here and be all "but vehicles do have rewind/replay" because that's what I have legitimately believed for the last, I don't know, 11 months? Then I dug through some code and of course I am completely mistaken.

    There are a few people who have looked into this and made some nice progress (HateDread and Acren come to mind, and I'm sure there are others). It's worth reading through their threads (like this one) and answerhub posts to get an idea of some of the challenges.

    To get to the point:

    1. I haven't seen one, but that's obviously (see paragraph one) not a good indicator of reality. If I come across something promising I will leave it here. Having realized that my vehicle game does not have rewind/replay implemented, I have decided to spend the end of this week and the weekend attempting an implementation for my projectiles and the wheeled vehicle class itself. I haven't looked into how to replay physics deterministically but the way the vehicle wheel states are currently replicated as a function of inputs seems promising, and I suspect the CharacterMovementComponent implementation will reveal how to correctly acknowledge move timestamps between server and clients.
    2. I glanced through some of the CharacterMovementComponent code again, and I think implementing the INetworkPredictionInterface makes sense. I authored the RVOAvoidanceInterface class and I don't think that you should implement that unless you're anticipating a need for Reciprocal Velocity Obstacle Avoidance. You can always implement it later you need it; if I recall you should be able to just execute it in one place (eg, the server) and depend on the movement component's velocity in order to supply an adjusted velocity.

    Before getting started I recommend reading Glenn Fiedler's Introduction to Networked Physics .

    Leave a comment:

Working...
X