NOTE: Updated for Lumberyard 18.104.22.168!
This level shows a simple example of one way to create a networked player controller.
- Extract the zip to your project’s Levels folder.
- Make sure your project has the InputManagementFramework and Multiplayer Gems enabled, if not, enable them, lmbr_waf configure and build.
- Run your game launcher and load the map using the console command:
- Next, start hosting using the console command:
- ALT+TAB back to windows explorer and run a second launcher which we will make the client. After the second client launches in the console run:
sv_port 0; mpjoin
The client should connect to your local server and you should be able to move the player capsule around. The reason why we specify sv_port 0 is so the second client uses an ephemeral port so we don’t try to bind to the same port that the server is already bound to. If you are connecting to another computer you wouldn’t specify sv_port, but would instead issue the following command to connect to the host:
NOTE: This sample was built for LY 1.9, but should work in future versions as well.
5084-test-network-player-controller-ly19.zip (31.7 KB)test-network-player-controller-ly19.zip
Of course this is all simple stuff, no user interface, prediction, smoothing etc.
How this works:
The level has an entity called PlayerController that has a camera and input components and spawns a Pawn. After the Pawn is created the PlayerController sends input to the Pawn to move it around. Because the Pawn has a NetBinding component and the TransformComponent has NetBinding enabled, the Pawn’s transform will be sent from the person that spawned it to all the other clients. This is client-authoritative which means it’s not good for preventing cheating, but it’s fine for prototyping.
If you want to implement network smoothing so the other hosts don’t teleport around, disable the TransformComponent’s netbinding and modify the Pawn script to send the transform from the controller to other clients using Lua NetRPCs and apply your position/rotation smoothing on those clients. Alternately, create a c++ component that does the same thing and add it to your Pawn.