Basic Player Movement
Assumption: You have installed all the dependencies from the previous step
Basic Scene Setup
Create the Manager Objects in your scene
(optional) Create a new folder called _Game in your assets folder so your assets are kept separate from imported assets
(optional) Move your default Scenes folder into that new _Game folder
Add a plane to the scene at orgin, Adjust the Camera and Lighting to your liking, add whatever else you want to the scene. Then save.
Create an empty game object at the root of your scene called NetworkManager and Add following FishNet scripts:
NetworkManager
Player Spawner
(optional) Tugboat ( fishnet will add this anyway as the default transport, just here so you know there are different transports that you can choose from.)
Set the 'Spawnable Prefabs' to 'DefaultPrefabObjects'
Find and place the /FishNet/Example/Prefabs/NetworkHudCanvas as a child of the NetworkManager you just created.
(optional) Add the Fishnet 'PingDisplay' script as a component on the network manager
Save Scene
Create the Player Prefab
Add an empty game object called 'Player' and add the following FishNet scripts:
Network Object
Network Trasform
add Capsule to the Player object as a Child to graphically represent it
Position the Player object slightly above the plane.
Create a prefab out of it:
create a prefab folder under _Game
drag the object you just created into
then delete the object in your scene.
Drag this player prefab into the player spawner component on your Basic scene network manager and save the scene
Test networking and spawn ( not movement yet )
launch the game in your editor and make sure that once you click on 'start server', then 'start client' the player spawns.
The player does not yet have movement added, we are just testing that it spawns and networking is working
If everything seems to be working and your project looks right move on to the next section.
Player Movement
Requires that you have installed Unity's new Input System package from the list of dependencies. It's a tiny bit more to set up, but it's superior and you'll want to use it eventually anyway.
Add the input bits to the player object and configure the input system.
Create a new script on the player prefab called 'PlayerInputDriver' (or whatever you would like I suppose) and save it in a new _Game/Scripts folder.
Edit the player input driver script you created to look like this
The above window is a properly configured input action assset from the Input System package. Follow the directions below to add the PlayerInput object to the prefab and configure unity events from the input package to hit your script methods.
During Step 2 of that process add an addition jump action as shown. .
Hint: for the binding use the 'listen' button where it says path and press space, then select what is shown.
Remember to press 'Save Asset' before you exit the input acton editor
Switch the 'Behavior' of the Player Input component to 'Invoke Unity Events'.
Wire up the unity events from the input system to the script you created as shown
Close the prefab to save it
Test
Fire up multiple instances using ParalSync or a build + editor. Have one of them be the server and a client, the others just be clients. Everything should work as expected for player movement.
Have a cold beer.
Last updated