How to train your pawn to replicate!
Hello all. I’m back and I’ve got all kinds of stuff to share. I’ll be posting here, then once everybody’s had a chance to take a look and give it a go, I’ll publish a nice tutorial to the Wiki.
Thanks to all who contributed. I’m absolutely shocked how well this works and how much fun it is to play with a frend or two in a game you’ve greated, even if it’s absurdly simply liek this.
What’s been done
- The 6-DOF pawn I built HERE has been made to fully replicate. Physics and movement are handled completely on the server.
- A simple attack has been made (Blast Attack!) that uses a physics impulse to blast other pawns away from the player.
- Tested on LAN and it’s very fun :F
Letting the server do it all
One of the first big problems I was having is that when Physics Enabled was set to true on the Pawn, there was some really wacky behavior. What other clients would see and what the player would see were quite different. The player would rotate a little and stop, meanwhile, the other clients would watch as the player’s representation would continue to rotate as if pushed by physics. If the pawn were on the ground, it would even roll about. Meanwhile, the player’s view was totally still, until they moved, then each of the clients would correct for a moment before returning to their physics drift.
Thanks to the videos posted by Ben earlier this week, I was able to understand that what I was seeing was the server replicating physics and sending that data to the clients while the local player was seeing the result of their input only.
My solution was bold, but has fixed my issues and allowed me to quickly expand the functionality beyond my original goals!
How it’s done:
Server-Only Physics:
I turned off physics COMPLETELY on the local clients. That means that only the server would be doing those calculations. this little line of Blueprint has changed everything for this test:
http://i.imgur.com/nfiQJev.png
Sending input to the server to handle:
Now, I just had to make Custom events that replicated from the Client to the Server each time there was input from the player:
http://i.imgur.com/9f6lETI.png
And, then do the actions I wanted to the pawn on the server. Each of these custom actions is set to Run on Server and has the Reliable box checked. I figure that input should definitely be replicated reliably, and should be a very small packet to send as I’m only sending the input value:
http://i.imgur.com/vuZkzv6.png
Getting the data back from the server to the payer:
At this point, everything was working really well… At least on all the remote clients. My arrows were zipping all over! However, my local player wasn’t moving at all. I’m assuming that because player input generally isn’t handled remotely, the optimized Replicate movement propoerty of pawns doesn’t bother. So, I made my own!
After struggling with the jerky, un-smooth replication of position and rotation, I tried replicating the entire transform of my pawn pack to the player. Smooth as butter! I know that this is a very expensive operation, especially at high frame rates, but it’s pretty essential for the player to have smooth, fast input. I’ll experiment with reducing this workload, but for now this works:
http://i.imgur.com/tNDda2p.png
And, that’s it! That makes it all work! Seriously. Here’s the entire Pawn’s Event Graph (The fancy Blast Attack is there in green. I’ll cover that next)
http://i.imgur.com/MdeH50W.png
And, here’s video of it doing its thang (Sorry about the low frame rate, it runs MUCH faster and smoother locally)!
SOURCE FILES:
And, here’s the project files as of the recording of this video:
Download HERE