I am creating a custom movement component for replicating motion of a spaceship. As I cannot use the custom movement component.
I have managed to set the position of the object on the server taking input form the clients.
But whats the best way to replicate it to the clients.
I am thinking to send input of the current location and rotation of the object to the client at some “intervals of time” and moving the object to that location per tick. But I want to know whats the best way to send the location data from the server to clients.
And if I send it at some interval of time, how do I decide which interval of time should be perfect for it.
Just make the variables Replicated, then make the Clients set their world Positon and Rotation to those new coordinates using OnRep_Notify or something.
It’s best to avoid using an RPC for this, since it updates so often, you risk sending a huge amount of RPC’s in small periods of time. Replicated variables will let UE handle how often those variables should send.
They do :), so so long as they’re changed on the Server, the Server will replicate them out to all clients (But only when they change). Bear in mind though, if they’re changed on a client they won’t replicate to the server or everybody else.
It’s a good idea to send them as FVector_NetQuantize too, to reduce the amount of bandwidth they use
FVector_NetQuantize = doesn’t store decimal places.
FVector_NetQuantize100 = accurate up-to 2 decimal places?
Also, any suggestion on how to interp the location on clients from server.
Should I instead of lerping between 2 locations, use the distance between 2 and the time difference between the updates to find the velocity and move the object with that velocity.
I think that might give some prediction with the movement and a bit smoother movement.
If your spaceship / pawn is extending from pawn? then I think movement interpolation is already implemented. I’ve read various answers on the answer hub that talk about this, but I’m not sure of the details. Here is one such topic.
That doesn’t appear to be the case, as far as I can tell.
The CharacterMovementComponent class has fully networked movement (with client-side prediction) built in for characters, and wheeled vehicles seem to work very well in multiplayer, but it doesn’t appear as if any other movement components have networking built in. If I’ve missed one, someone please let me know
It’s not that hard to do, though. I was able to get it working in a couple of days, and that was while re-acquainting myself with C++ and (still) learning the Unreal engine.
I think in the AnswerHub post, he was referring to the character movement component.
Another important thing? When interpolating between 2 location, do use a timer that store the time after which the location replication takes place and use it to calculate the velocity. Or do you replicate the velocity separately?
I replicate only position and rotation information, along with a timestamp for each update. On the client I keep an incrementing time value that is used to interpolate between two such movement updates, so a seperate velocity isn’t really needed.
It was a bit Slow/inaccurate and sometimes it kept rotating without stopping.
I replicated using FQuat and interpolated with Slerp seemed to solve most of the problems. Now only thing left is client owner side prediction. I think it would be the most trickiest part.
The only working example I know of is the CharacterMovementController class. But since it is not written in a manner meant to demonstrate how it works, and uses poorly documented (or completely undocumented) engine functionality, you have to be smarter than me to figure it out apparently
I’d be curious to hear about your experiences in implementing that.
In my case, since my Vehicles are Physics-based (but not part of the PhysX system, I just use Unreal’s functions to update the physics of the object), it’s important for me that movement is handled Client-Side, but simulated server side and authoritative positions are sent back.
I do two things, I not only have ‘Replicated Movement’ switched on, which handles to location setting side of things, but I also simulate the Input from the keyboard on the server as well. This costs less than CharacterMovementComponent’s methods from what I’m seeing so far. I’m also planning on copying over Unreal Tournaments overridden ReplicatedMovement functions later, since they’re more optimized than the Engines version.
WheeledMovementComponent is where I got the functionality from. It’s also considerably easier on the eyes than CharacterMovementComponent is Look at the ‘UpdateState’ function. It simply updates the clients input values to those the server is simulating, but movement is first done locally, so you get smooth movement.
So far, really nicely optimized. I had a look at the network profiler and I’m using less bandwidth than CMC’s methods. Happy with that!
How do you open the netprofiler? I cant find it inside my Engine\Binaries\DotNET
Also, if you handle motion client side, wont it lead it be easily exploited and hackable?
I am confused On what exactly does setting “ReplicatedMovement” to true do? Does it replicates the action that happen on the server to other clients? I tried that and it didn’t work so I had to replicate the location manually.
So what I basically understood is, you handle to movement on the owner client. Send the information of the movement to server. The server then checks it and sends to all other clients except the owner client. Right?
That’s odd… are you going to the engine installation directory (not project directory)?
As for the motion issue, it’s not a problem because the server regularly updates the clients position using replicatedMovement. I’ll get onto that…
ReplicatedMovement is a struct that contains a few parameters, location, rotation, velocity, physics state etc. Not much more. When you check ‘ReplicatesMovement’, all you’re telling the engine to do is replicate that struct out from the server to all clients, and force the clients to match the data in that struct. Basically, the server sets the location on all clients to what it thinks it should be, so everybody remains in sync, and nobody can ‘cheat’ or go out of sync for more than a few milliseconds, depending on how often the server is updating clients.
Basically, I handle movement on both client AND server, so that the clients get immediate feedback on their screens. The server then also sends it’s own version of the movement back to the client, which is then force-updated regardless of what the client is doing. CMC actually does the same thing, movement is done locally and server-side, then the position is replicated back from the server, to make sure the client hasn’t ended up somewhere they shouldn’t have.
This is basically how you can end up with Rubber-Banding. So if the clients move somewhere and the server doesn’t think they should, they get forced back to where the server thinks they should be. This would rarely be seen unless your connection is extremely laggy, but then players can’t expect a good play experience on a laggy connection anyway.
Wait that is weird. I have replicated movements and the object moved on the server and didn’t move on the client so I had to write my set of code that worked exactly like replicate movement. The object moves on the server and not on the client.