I was looking for so long time how to make custom movement prediction by Blueprint Settings and i didnt find anything in Unreal Answers, so i will give some solution to people who is looking for it and cant solve by himself or doesnt have pattience (if u are doing a MMO with vehicles or spaceships, like i am doing, u cant let people with 150 ping ask server and receive duplicated movement, cause they wont control his vehicle, and less with high speed, movement is so laggy and people will hate it, even if it disables cheating, is like, i cant play, i cant cheat, i cant do nothing hahahaha)
When started to make my custom one, first i looked for some Rama’s Physics explanations, then i looked for a lot of articles of physics replication and client-side basics, network interpolation and lag compensation, and i thought it could only be done by C++ cause i didnt find answers, but later i can check this is not real, same as “lot of pawns Lag”, it is not correct (i explain this later too).
Doing pawn movement client-side was too easy after reading information on how to do it, but the problem was on Wheeled vehicle movement, which gave me lot of problems at beggining, but i finally understood everything.
First of all, when i check duplicate movement flag, it was laggy at driving with player controller, owner and even netowner priority, but i saw something what gave me to test like 300 times in 4 days with that vehicle, until i got it, if u could notice, vehicle gets moved local but later update in server ur input doing it later so there is the “lag” in online. U can activate physics on server if u want Server-side Vehicle, to not see that lag, but u will have lag until server response arrives and input is not instant.
If u try not to replicate movement of vehicle, then vehicle goes local instantly, but it updates so bad in other clients so vehicle desyncs. This was a problem, but i got how to put Local control instant, duplicate movement must be unchecked to achieve this.
The synchrnize problem was a big deal, cause i cant do nothing with it, cause setactorlocation didnt move physics, but like always, u start to know how to do it, if u tryhard (tryndamere life). If you set base of vehicle as Mesh (inherited) you can teleport it with SetWorldLocation of mesh component, the base of pawn vehicle, and Check Teleport(so important), cause this was a fix by Unreal developers to teleport physics without C++ Setphysicslocation or something like that, i saw it in a post in Forum time ago.
Now that we have teleported it in Singleplayer (play without dedicated server to see if it works), we need to set it in server, which is a problem if u dont know how to do it from first time. If u teleport with custom event in server, u will see it goes always to 0.0.0 or it doesnt goes even, it depends xD. The solution? Do a custom event on server and later in that event play other Custom event on all, this way it updates for everyone (and server, important).
Now u have to setactorlocation to client location, how to do that? It looks easy at begin, is easy to think how to do a system with that, but later when u give getactorlocation directly to setactorlocation, boom, u go to SERVER location, and u will se so buggy, cause u update position on ur client without movement replication checked, but on server it updates from other way, slower and Desyncs so car will go laggy if u do this.
Enter, Enter, xD, to replicate variables u need to get em from local, so u need to make a custom event on client to get HIS CLIENT actor location and later set Vector variable (use set world rotation and location to give 100% performance, rotation is essential too, but i am explaining with location only cause yes). When u set vector variable in client u do it instant, so u reproduce instant location of you, but u have to send it to server to other variable vector (and rotation) to update on server and later custom event on all to move it to the designed position.
This looks easy too, but when u set all then it teleports to 0.0.0 again and stucks, bug etc. Guys, u have to make 2 pins in Custom event on server (which updates vector and rotation on server before move) and link rotation and vector (replicated variables) on pins to give server the real position of client, and not reproduce 0 0 0, cause cant replicate.
After this u have that yeah, not that hard no? I dont know if this goes with add impulse or something, but if something can be done on client it will be done instant and later replicate position from client.
We have now to put the function to vehicle time (ticktime). U can get by casting to game state the ping, so u are able to get ms and then reproduce everything having that time in mid.
I wont put a photo por now, cause i dont know if this will be sawn by everyone, but i will help u giving images and video working out if u need.
Now, you are teleporting to the client location but with some ping u do it like laggy, obvious cause we were testing features, and only have one variable who takes from client to server to order server to move client to where he wants (is like corrections). Now u have not to do a Replay/Rewind system like shooting, u have to do a future prediction, which has lot of optimizations to be done (is not as easy as putting some code and yeah i have prediction done!!! hahaa)
I didnt see tutorials to make prediction future, but here is the simplest way, i will be wrong so i hope u correct me in something guys too ! :P, i am a noob yet in ue4, only 3 months.
- Tick every ms=0.001 . If u want to ping each 2 or 3 or 4 ms u only have to x/1000 and u get the cyphre of the time, later divide ping beetwen x to obtain correct step.
- the function to tick is Add to array, u add location and rotation (transformation) to an array and then u have replay system and Steps (there are tutorials of replay with steps, if not ask me for it). U can go to each step of that actor to reproduce even a video (at the velocity u want) like a replay in the world, but it isnt what we will do here hahaha. Not this time!
- U take real ms (the cyphre u took from x/1000), then u getactorlocation(and rotation, or transform, etc) on client and sustract it with step real ms (you can take delta time or seconds on server from gamestate to check ping if u have problems) and u do a sum with final location checked in client, so u give the server the next probably location of ur vehicle.
- Later u will have problems only with direction hard changes ingame with lag, when the vehicle is running it will go incredible well (u can take a variable to correct speed at the time too), but on direction changes u have to touch manually that valors to be more to left or more to right.
- IMPORTANT: U dont have to update all the time, u need to update it sometimes, so if u do that u will only notice lag when updates, and clients will see it synced cause to desync it gives so much time, u dont desync a car for driving in a line, u desync with brakes, deceleration and physics changes, so game will go how u want.
About the other thing i said i would explain, npcs, is just, people in forums cry for fps drop, ping, etc, with pawns. If u use pawn float movement it goes so ■■■■■■■ well, only add gravity with secactoroffset and u have a perfect npc, which respects navigation, u can give him even fly or jump events if u want, by manual obvious. If u see laggy npcs u can do prediction to em, in a pawn is lot of easier than a physic body, cause aceleration is always the same. I can take in my game more than 300 npcs with only 10 ping to clients, even by hamachi 20-30 ping with far distance connections, and more than 60-80 in your screen, and yes, they move all the time :D.
I am in love with Unreal development, and i keep being in love with Unreal 2, best game of all. GG WP