Transcript for:
VR Multiplayer using Fusion 2 - Part 3

hello everyone welcome back on this channel guys I'm raming Unity developer YouTuber and blogger so friend in today tutorial we are going to do part three of VR multiplayer using the Fusion 2 as well aspler me so this part is going to be we will create a small UI also we will just complete the player spawner script where it will help us to spawn the player and also there was so many call back so let's start the today video if you are new in Channel make sure to subscribe the channel you can also join this channel if you want to support and you can also become the patreon on my page also you can grab any samples if you want and this sample like whatever we are doing tutorial it will be uploaded here after the completion of this series let's start the today video if you want to check out me so you can just check out me on my LinkedIn profile so here you can see we are in game and we have created one scene that is the game area so here we are doing all the things and here is the player spawner so I'm just going to open but before opening what we have to do here we have to park is the network Runner as I told you and last tutorial that we have to a manually here seing for Network Runner so just by default we have added this one and add enable visibility so you can on this one so there's no any issue with it and just open this script and here what we can do so here we can sign our players so here is the player just assign here when this is so basically in last tutorial we done that how we can create the room and then we have also provided here reference so we have passed the reference now it is time to player instanciate so here you can see we have got so many call back so we have to utilize some we will utilize player join and as well as we will utilize player left basically these are the two and we can also use this third part on input we will transfer from input here to other player device we will talk about later on this thing in my previous series you have not watched so I will request to watch because there are so many Concept I have shared on this so you can check out internet is not working just open this script and we will write the code here go see that is a player joint so basically here we have to write some code so many call backs so if you need you can reuse them but currently it is not necessary for us so just I'm going to utilize these two things so here what we have to do here we have to get the positions so you can use the vector and player position so basically I'm doing simplest thing to not wasting your time so you can do so many stuff like you can get many game objects in the this area so it is very empty so let me add something so that it looks great here is the plane and position you can do like reset position so it will be on zero position and you can do five and you can do five basically for the position you can take multiple game object on multiple places in the array and then you can give any position from them so it is a basic concept you have to do yourself because uh I'm not going to do I'm going to do very simple thing that is the vector 3. Z means on the Zero position I going to instantiate my player and for instantiating my player I have to use Network object Network object here it will player reference and here we will use what we will use use Network Runner so we use Network Runner dot spawn so basically it will ask few parameter will be our player reference we can say player prefab player prefab so here is our player prefab and here we have to pass our position so basically here you have to grab the position and on the basis of that you can pass here so it's depend on you so here we can pass the player position so simply just use this one now we have to pass the rotation so we are going to use IND dot can use the ident and here we have to pass this reference player reference so as for many parameter basically it is a reference so you can see it's ask for many parameter uh list which we have created here so here is the spawn characters so we have to utilize this one on characters and we are going to add so player reference is this one so we will pass the player so this is the key and value will be our player reference so use player reference okay so we are here on the player joint we have done this part and one very important thing I want to tell you that we are doing host and client mode so you have to understand that whatever state syncing like whatever you are giving input so you have the input Authority but whatever you are giving so server you can say host have authority to just INSP spawn the player or just transfer the any input system so here you have to one if condition what will be the condition so you can check Network runner. server so if it is server like if it is host or server basically host and server you have to understand that you're in the game you are hosting the application so it means that you are the host you are the server and if you are joining so you are the client and if you are hosting from a particular hosting service provider website or server services so at that time that will be a uh that will be our server and you as a player will be joined so it is not that much complicated so I'm not planning that thing I have explained in a very deeply in my series here we are testing and here you can see that host or server have authority instantiate the player host or server the host and server topology is same the host you just inst you just start the game from the application in the server mode basically you just host your server your application in the future we will talk about that but we not in the series so let's see where we are going and here on the player left so basically it is for join so whenever player will left basically we have to get null so at that time dictionary so we can use I get value that will be player and then this will be Network object so you can see out Network object and this will be simply Network object okay so basically we are trying to get the value that player means this reference and it is the kind of network object so what we are doing so we have to despawn so basically we have to use Network Runner dot d spawn and then this will be your network object and and we have to delete this object from the this so you can use remove and then you can use this player reference basically it is the key and this is the value okay great so now we have done the player instantiate part this script is almost ready we have passed the references here the network Runner and we have to just instantiate this one so let's suppose I'm running from here so what is is going to happen so here you can see we are able to run but we don't have something what that we are hosting or we are joining so we have not done those things so what we have to do so for the simplest thing all the networking thing I'm doing here this area what we have to do we have to create a basic U so I'm separating the scene so that you have a basic idea that what I'm trying to do that is the very simplest thing so I want to make you sure that you are understanding the core concept so here we have to take one canvas so take one canvas here we can take World space you know that everything works in the world space and it is just turned on so that we can see how much it is big and you can just reset the value So currently it will be in this area okay and now we have to use 0.01 because it is very big according to World space so here you can see this is the size and we want to take the panel so take one panel so that we can see properly okay so now I think it is uh right place join and host okay and here I have one script so basically we have to attach canvas so to save the time I have created this script that is the choose mode so whenever you want to want to play here if you don't have so many player so you can choose from here like you want to host so you can choose host if you want to join so you can want to join but if you want to just want to go inside on the basis of the player choose join button or host button so you have to click here or here then it will work but if you don't want to click here so basically you have to choose host or join on the basis of that if you are hosting so you have to choose host otherwise you have to choose join otherwise it will be none okay so basically we have done this part and whatever we have taken the button here so we need our canvas so add this and here we have the canvas because we have attached this script here so for the join you can use multiplayer host multiplayer so here is the host multiplayer and just let me go through this script so that you know that what we have written so basically it is the just NM type none host and join and this is the basically connection type which kind of connection we want so here you can see that if connection type so basically it is a connection type it is on the basis of that it is getting here and if it is connection time none so we have to not do anything it will work on the basis of UI selection and if it is connection type host so at that time we have to use host multiplayer if it is joins so you have to use this one and what we have written here so basically we have used the player perhaps so that we get the value that what we are doing here is the on start it will be always set to mode zero because it is the key in the player fs and here is the gate mode so basically in the start it will call on the basis of that what selection you have made here okay so on the gate mode on the basis of that here you can see it is the host multiplayer so basically what we have done if it is host so on the game mode we are doing one because we want to know that if it is host host so game mode will be one if it will be joined so it will be two so if it is joined so here you can see we are passing set value game mode two yeah okay so here basically we are loading the scene okay great so this was the basic samples and done all the setup but in this we have not do anything on the player respond what we have to do so basically we have to call this method and here we have to pass so here we have to write two method that is the W so in that case we have to pass so basically in this mode first we have to check is not equal to null so at that time we have to call start game and this will ask about game mode so you can say game mode and this will be client okay and same we want to do so just copy player joint as a host so basically it is hosting so just uh okay great so basically whenever this scene will be load so we have to call this methods so here you can see we have not edit the start method so if we can use click void and this is the start and here what we have to do so basically we have to write this code like we have know that game mode will be two so at that time we have to join multiplayer so basically we want to just call our this method whenever we want to join as a client so call this method and here player joined as a host so at that time we have to call this method whenever we are loading this in so we have to call this so that on the basis of selection we perform this task okay so if game mode will be two so it means we are joining as a client if it is any other thing so at that time we are just hosting the application write the code and everything is good here so here you can see everything is good here now we have to instantiate the player so let's see how it is working so for this we have to go on the RPM demo and we have created the UI but currently we are not using so I will create the build and I will show to you that how that is working in next part but currently I'm just doing the host and let me choose and here you can see one thing I want to share on the fusion on the real time setting is the fixed region so if you want to join always in the same region in the same room so you have to do something a fixed region so you have to see that which region you have So currently I'm nearest to Asia so I'm using the Asia so that we always join in the same room with all players okay so let's suppose I am just host hosting and here you can see on the choose mode I have do the host thing okay so currently we are not able to load scene what's happening so let me check so here you can see we have not given the scene where we want to go so just go and a game area here now it should load the scene so let's see how it is working so currently we are loaded this and let's see our player is getting spawned or Not So currently we are not able to instantiate our player so let's see and what is going on here okay so I just C the errors what I was doing mistake so here you can see on the player join is a host and player join is a client so I'm checking that Network Runner is not equal to null so at that time I was doing but that is wrong you have to do equal to equal to null because whenever you are starting the scene so at that time Network R will be null so at that time it will be called so just make sure that you have done this thing after that you have the network Runner and then after that you can check so I think that will work okay so let me check again let me check again and what going on and in next part I will show to you in the VR but currently we are doing here so anything will be not seeing So currently it will be just instantiate so make sure you have on the canvas you have done the host and then you have click here we are hosting the application so we are just loading game area and here we got our player so here you can see this is the local player we have changed the name by using the player setup and currently it is Network object we have added all this thing so everything is looking great So currently we are able to instantiate our player so nothing will be seeing because we have not done anything so our player is coming like this so whenever you will wear the headset so it should fix or maybe we have to do something thing with the V ik to initialize as a local player so we will see in the next part so currently we are able to instantiate our player so see you next video and don't forget to like subscribe and share your like really inspire me to do much more tutorials and please support to become the patreon so that I can continue my journey you can also grab anything you want to from here for anything useful for you so see you on next video bye-bye take care