[TEMPLATE] Multiplayer TopDown Template C++

Hey guys,

just gaging interest levels. I just finished creating a basic version of the TopDownTemplate but Multiplayer since the original version is not compatible with Multiplayer. Using the same theory as mentioned here: Does UE4 have client-side prediction built in? - Multiplayer & Networking - Unreal Engine Forums

It uses AIController Pawns to move your character around and so far works quite nicely.

If anyone is interested, I will clean and upload to github for everyone. I am not planning on making any money with this. Just helping out as I have been searching like a “crazy” person and finally figured it out after about 2 days of head banging.

Click the github link below and feel free to extend / use as you see fit.
GitHub Repo

Could be useful in the future so subscribed

I also made a basic multiplayer version of it, simply by running pathfinding stuff on server, and apparently works fine, I had only problem with character rotation replication, but it was easy to resolve. In theory ACharacter features some movement smoothing for network games, but I would be interested in what you created.

thanks!!!:slight_smile:

I have made it public on github, just check the original post. Rotation etc all is working as it should.

Will def check this out. :slight_smile:

I don’t really understand why it is better than simply in PlayerController do a check on button press IsLocalController() , and if true make ray tracing and target setting locally on client, then call a server function and passing this new location, where you do the pathfinding by NavSys->SimpleMoveToLocation(this, DestLocation);
by the way, you could add hiding the decal component of the character on BeginPlay() if the controller is not IsLocalController()

Like I had said this is ONE way to do it, I didn’t say it is the ONLY way to do it. With that being said, it was mentioned multiple times WHY SimpleMoveToLocation was not intended for Multiplayer and should not be used as such. (by Epic Staff btw). However what I wanted to achieve was an architecture where the Player would never host any game but all would come from a dedicated server, and that is what I have achieved, e.g. every player gets his own Character (controlled by AI) to posess and control.

Here is a Quote from the EPIC Lead AI Programmer on this topic::

So I took what he said at face value and trust in his words. You can also take a look at the thread on answerhuib where people discuss the blueprint and play around with SimpleMoveToLocation etc and they all encounter issues.

Thanks, I think I understand now :slight_smile: After reading your description, now I remember I had also problems with SimpleMoveToLocation and player controller controlled pawn, namely player characters are out of the Detour Crowd avoidance system, thus AI characters can get stuck at player characters (no avoidance only collision), and vica versa, what you solved by using AIContoller for the player too. Great!

I know this is a (seriously) old thread, but this approach is the same as mine (all pathfinding/movement done on the server). I’m still having trouble with rotation, however. The server works fine (as expected), and every client except the active one shows movement and rotation correctly. For the current client, however, the character moves to the target point without problem but it always faces the top of the map. I am running multiplayer from the editor with three players (server and two clients). When I select a client, its character won’t rotate to face the direction of movement, but on the server and the other client, the movement looks like it’s supposed to. There must be something in the client code that is overriding the server’s direction and not allowing the character to change facing, but I can’t find it. Can anyone help?

I used code from Tom Looman’s Survival Game to resolve it, see aicharacter code. Or maybe the Shooter example game. Tomorrow I can check this.

If you could take a look, I’d really appreciate it. I’ve looked at Tom’s code but the answer still eludes me. Thank you.

@Dijon
I’m calling this from AICharacter Tick() function if (Role == ROLE_Authority) as Multicast_SetRotation(GetActorRotation());

void AOGWAICharacter::Multicast_SetRotation_Implementation(FRotator NewValue)
{
LastYawRotation = FMath::Abs(FMath::UnwindDegrees((NewValue.Yaw) - (GetActorRotation().Yaw)));

SetActorRotation(NewValue.Quaternion());
}

@sivan
Thank you very much for the help. I’m curious, however, if you’ve missed a step. You calculate LastYawRotation, which is a float, but don’t do anything with it and instead use NewValue that is passed to the function. Am I missing something obvious?

Hi,

I just used your template but I have some very bad issues :frowning:
In the editor looks great don’t have any problem and it’s smooth. But if I run it outside of editor with built dedicated server and client connected to that it’s very choppy.
See : https://www.youtube.com/watch?v=PuZkTyst2bM&feature=youtu.be

Do you have any idea how I can fix it ? Or this solution is just not correct ?
Many thanks for help.

I have been away for quite awhile and tbh suuper busy atm.

@Vaclav take a look at
Transform.LerpTranslationScale3D(CharTransform, MyTransform, ScalarRegister(0.01f)); in TDMPCharacterProxy and lower it so something like 0.005f maybe and see what happens then. I had this stuttering when I set the value to 0.5f etc.

CameraBoom->bEnableCameraLag = true;

Enable camera lag and you are gucci.

Lols. Very funny byt very bad at the same time. Hopefully nobody will be confused by your wrong reply.
Anyway this is 4 years old so it’s already sorted :slight_smile:

Can you tell me how you sorted it? :slight_smile:

Enabling camera lag sorted it for me until I increased ScalarRegister to 0.5, then I also had “Default Land Movement” to None.