Photon Fusion 2 Unity Multiplayer Basic Tutorial for Beginners | EP.06 Collecting Input & Ticks Use
Summary
TLDRIn this Unity game development tutorial by Ram Singh, viewers learn how to implement input handling in Fusion 2 with host mode. The video explains the input system's operation, the importance of host authority in updating network movements, and the creation of a 'NetworkInputData' script for local player movement. It also delves into the concept of 'tick' in multiplayer games, which is crucial for smooth gameplay, and demonstrates how to apply these concepts to move a player character across a network. The tutorial is designed to help developers understand the basics before exploring advanced features.
Takeaways
- 😀 Ram Singh is a Unity game developer, YouTuber, and blogger.
- 🔄 The tutorial covers how to work with input in Fusion 2 using host mode.
- 🎮 It's important to understand the basics before exploring advanced features in Unity.
- 📱 The input system involves a local player creating an input structure that is sent to the host for network updates.
- 👤 The host has the authority to update the network, while the local host handles the actual movement.
- 🔄 Host migration is possible in Fusion 2, allowing any player to become the host if the current host disconnects.
- 📝 A script named 'NetworkInputData' is created to structure the input data for the local player's movement.
- 🏗️ The use of 'struct' is preferred for lightweight data over 'class' due to its simplicity and lack of inheritance capabilities.
- 🔑 Key codes are used to capture input from the local player, such as movement with the WASD keys.
- ⏱ The concept of 'tick' is introduced as a way to update clients or servers in a multiplayer game environment.
- 🎲 A higher tick rate results in a smoother game experience, as it involves more frequent data exchange and state synchronization.
- 👾 A 'NetworkBehavior' script is used for player movement instead of 'MonoBehaviour' to receive movement data from the host.
- 🔄 The 'UpdateNetwork' method is overridden to get input from the host and perform movement on every tick.
- 🎉 The tutorial concludes with a successful demonstration of moving a player in a multiplayer environment using Fusion 2.
Q & A
What is the main focus of this tutorial by Ram Singh?
-The main focus of this tutorial is to explain how the input system works with Fusion 2 in host mode for multiplayer game development in Unity.
Why is it important to understand the basics before exploring advanced topics in Unity game development?
-Understanding the basics is important because it provides a foundation that allows developers to comprehend and effectively utilize advanced features without confusion.
What does Ram Singh suggest for new subscribers who haven't watched previous tutorials?
-Ram Singh suggests that new subscribers should watch the previous tutorials to understand the basic terms and concepts before exploring advanced topics.
How does the input system work in Fusion 2's host mode according to the tutorial?
-In host mode, every player has the authority to get input, but only the host can update the network. The local host creates an input structure that is passed to the host, which then updates the movement on all other devices.
What is the role of the 'Local Host' in the context of the input system explained in the tutorial?
-The 'Local Host' is responsible for capturing the input from the local player's controller and creating an input structure that reflects the player's movement, which is then sent to the host.
What is meant by 'host migration' in the context of multiplayer games?
-Host migration refers to the ability for a different player to become the host in a multiplayer game session, allowing for the game to continue smoothly if the original host disconnects.
Why is it necessary to create a 'NetworkInputData' script in Unity for handling player inputs?
-The 'NetworkInputData' script is necessary to structure the player's input data, such as movement, which is then sent to the host to be updated across the network for all players.
What is the difference between a 'class' and a 'struct' in Unity, as mentioned in the tutorial?
-A 'class' can inherit interfaces and is used for more complex data types, while a 'struct' is a value type used for lightweight data and cannot inherit interfaces. It is stored on the stack and does not contain references.
How does the 'tick' concept relate to the smoothness of a multiplayer game?
-The 'tick' represents a single iteration of the game loop, and the more ticks that occur in a second, the smoother the game will be, as it allows for more frequent state synchronization and updates.
What is the role of 'NetworkBehavior' in controlling player movement in a Unity multiplayer game?
-The 'NetworkBehavior' is used to override the 'UpdateNetwork' method, which allows the host's input to control the player's movement on every tick, ensuring synchronized movement across the network.
How does the tutorial demonstrate the application of the input system to a player character in Unity?
-The tutorial demonstrates by creating a 'NetworkInputData' script for input collection, applying 'NetworkBehavior' to the player character for movement synchronization, and explaining the importance of the 'tick' for smooth gameplay.
Outlines
🕹️ Understanding Input Handling in Fusion 2
In this paragraph, Ram Singh, a Unity game developer, introduces the topic of input handling in Unity's Fusion 2 with host mode. He explains the basic concept of how input is captured from the local player and then sent to the host to be updated across the network. The importance of understanding the basic input system before exploring advanced features is emphasized. The tutorial is aimed at those who are new to the channel and have not seen previous tutorials, as it builds upon foundational knowledge. Ram encourages viewers to subscribe and like the video to help the channel reach a wider audience. The explanation includes a diagram to illustrate the process of input from the local client to the host and then across the network, highlighting the role of the host in managing input updates.
🔄 Exploring Tick Rates and Player Movement in Multiplayer
This paragraph delves into the concept of 'tick' in multiplayer games, which is a crucial element for smooth gameplay. Ram explains that a tick represents an iteration in the game loop, during which data is exchanged between the host and clients, facilitating state synchronization. He clarifies that it is possible for multiple ticks to occur within a single frame, which can significantly impact the game's performance. The paragraph also covers the creation of a 'Network Input Data' script to handle player input and movement locally before sending it to the host for network-wide updates. Ram discusses the use of structs for lightweight data and the importance of proper coding practices, such as using curly braces to avoid errors. The tutorial progresses with an explanation of how to apply these concepts to player movement in Unity using Network Behavior and the Network Character Controller.
🎮 Implementing Player Movement with Fusion 2 Multiplayer
The final paragraph focuses on implementing player movement in a Fusion 2 multiplayer setup. Ram provides a step-by-step guide on creating a script for the player that overrides the 'UpdateNetwork' method to receive input from the host during each tick. He details the process of obtaining direction from the network input data, normalizing it, and then using it to move the character controller within Unity. The movement is synchronized with the 'Runner.doDeltaTime' to ensure it is consistent across the network. Ram demonstrates how to assign the script to the player character in Unity and encourages viewers to test the setup in a multiplayer environment. The paragraph concludes with a brief test of the player movement, showcasing the successful implementation of the input and movement system discussed in the tutorial.
Mindmap
Keywords
💡Unity Game Developer
💡Fusion 2
💡Host Mode
💡Input System
💡Local Player
💡Remote Device
💡Network Input Data
💡Struct
💡Tick
💡State Synchronization
💡Network Behavior
💡Host Migration
Highlights
Introduction to the tutorial on how input works in Fusion 2 with host mode.
Explanation of the importance of understanding basic concepts before exploring advanced features.
Description of the input system in Fusion 2 involving two devices: a local device and a remote device.
Clarification on the role of the host in updating movements on the network for all players.
Illustration of how the local client creates an input structure that is then updated by the host.
Introduction to the concept of host migration in Vision 2, allowing any player to become the host.
The necessity of creating a 'Network Input Data' script for capturing and moving the local player.
Discussion on the difference between classes and structs in Unity, with a focus on using structs for lightweight data.
Instruction on collecting input data from the local client using Unity's Input.GetKey method.
Emphasis on the correct use of curly braces in code to avoid common programming errors.
Explanation of how to send collected input data to the host for network synchronization.
Introduction to the concept of 'tick' in multiplayer games and its role in smooth gameplay.
Description of how a higher tick rate can lead to a smoother gaming experience.
Discussion on the possibility of multiple ticks occurring within a single frame.
Explanation of the tasks performed during a tick, such as state synchronization and physics simulation.
Guidance on creating a 'Player' script using Network Behavior for movement in a multiplayer environment.
Demonstration of assigning the 'Player' script to a character in Unity for multiplayer testing.
Conclusion of the tutorial with a successful demonstration of player movement in a multiplayer setting.
Transcripts
hello everyone welcome back on channel
guys I'm Ram Singh unity game developer
YouTuber and blogger in last tutorial we
learn that how we can spawn our player
inside the room in this tutorial we are
going to learn how input thing work in
the Fusion 2 with the host mode so let's
start the today video if you're new on
the channel make sure subscribe the
channel if you have not watched previous
tutorial so make sure that you have
watched because it is a very important
thing that you understand the basic
after that you can just explore any
advanced things so that uh you know the
basic term you know the basic B to
create the room to get the input that
you can explore the advanced thing so
let's start the today video supporting
me you can just join or give me thanks
or just if you you can't do anything so
please like the video so that I can
reach much more people like you in this
tutorial first we have to understand
that how input system work with the
Fusion 2 so basically what happens is
that let's suppose we have two devices
that is my device that that is the
Remote device and this is the me local
player on my local device B1 is the I'm
getting input means whatever I'm using
my any controller and then what I'm
doing is just I'm just moving in my
local device okay and creating one input
structure that thing I have to turn to
host and then host will just update my
movement on another another device like
in this P1 so here you can see I'm on
the P1 and you can you can see same
structure uh getting on the P1 okay so
basically in the host mode what happens
that host means every player have the
authority to get the input host have
authority to update on the network but
Local Host have authority to get to do
the movement but it is not on the
network basically it just provide the
structure to to the host and host update
on the all Network so hope you
understand so here is my device I'm
getting the input so my player is
getting mve locally and I'm creating one
structure what is my movement and that
structure pass to the host and host
update on the network means on on all
other devices so this is the way to get
the input so this was the just diagram
hope you understand what I'm trying to
say host and you can call this is the
local client this is the client so these
are the client and you also know that
host migration also work in the Vision 2
basically if this host out so this
player can be the host okay so this is
the way of host migration this is the
way to get the okay great so let's jump
into the unity and here we have to
create one structure where we can take
the input so basically we have to create
one script that is the network input
data so basically this will be the
structure that will take the input and
move the our local player and then this
will be provided to the host that will
update on the network you can remove
this thing and here is the class we want
data that is the data structure what we
want we want the movement in movement
what we need need we need Vector 3 where
we want to notice XY Z Direction
movement so for the Simplicity for the
lightweight data we use the stru struct
struct we cannot inherit we cannot
implement but I Network input I am just
inheriting so in the comment box you
have to let me know that what is the
difference in class and struct basically
struck is structure so basic difference
is that we cannot inherit any uh
interface but we are inheriting so you
have to also let me know that why we are
doing this and this is the homework for
you and the basic difference is that we
cannot inherit and basically struct we
use for light weight data means we want
to few similar kind of data types so at
that time we use the struct we have not
to create the object and it does not
contain the reference so that's why
store in the stack so there are so many
differences and in interview people ask
so basically what we want we want our
Vector 3 so just do the vector 3 this
will help us get the direction this is
is our structure of of structure of our
input whatever we are getting and in
locally we will move but on the network
host will uh do the update so basically
this will be provided to the host okay
great you have to not worry about the
compression basically us to compress the
data before sending and it only send if
it is getting any differences in the
input okay so next step is to collect
the input from the local input from the
local client we have to go in the basic
spawner because we have done so many
call backs here so we have to search on
input so on input what we have to do we
have to just create where data and
basically what we have to do new network
input data that what user is pring so
basically we have to use input get key
then we have to use key code basically
key code provide the button so for the W
and what we want on the W basically data
and then we have we need direction and
plus we have to use Vector 3 do forward
so similarly what we have to access we
have to access w a DS so make sure you
have just Ed the code s code A and D
never write this kind of code because in
most of cases what happens that you have
not provided the curly braces so it WR
single time uh single line line of code
make sure someone have done this or make
sure that someone have write any line of
code this code will not work at that
time you can face a problem so make sure
that you have used every code the curly
braces Above So alt and arrow so make
sure that you have pass all the key WS
for back for left D for right okay so we
have collected all the data what we need
so we need to send to the host so what
we need we need Network input so here is
the input here we have input input we
have to use to set data so basically we
use set and then we have to pass this
data basically what doing is just
passing to host so this code is getting
collected locally and then passing to
the host okay great now it's time to
explore one more very important Concept
in the fusion so it is a very important
you have to understand and after that we
can go further and then use one code so
that you can understand so this is my
device so you can call me client or you
can call me host and here is one other
that is the host server or you can call
client so host and client can be anyone
so don't worry about it and there is
another device that is also client okay
great so what is the tick so you have
most probably heard in the multiplayer
what is the tick tick player very
important role that you have heard that
tick value is more your game will be
more smoother so what is the tick so
tick is like on is a in simple way is a
way to update the client or server or
host so let's suppose this is my device
and one Loop is running so let's suppose
from here we are starting then we are
coming here here basically Fusion what
does is just run one Fusion just run a
continuous loop in your application in
one itation means whenever it complete
one iteration that is called tick what
calls tick means every device every
client every host every server run
continuous loop and in continuous loop
one completion or one itation is called
take and in one tick one tick what
happens just it exchange the data
between the server or host to client and
then every like server also run their
tick so in one tick means basically one
iteration they just uh send data to
client uh whoever is connected to the
device it just send data and get receive
the data data basically they perform
State synchron basically they perform
State synchronization physic
synchronization input synchronization as
well as
computational logic synchron means in
one in one tick they exchange the data
and what is the one tick one execution
or one itation of loop basically uh it
performs always then people ask me that
that it is possible that in one frames
what is one frame like in 1 second how
our our rendering is happen like our UI
our 3D message render so basically
people ask me that in one frame it is
possible that multiple tick play so yeah
it is a simple it is possible means one
frames multiple dick can be performed
okay and in most probably it happens
because if it will not happen so your
game will be very laggy the number of
tick is higher so your game will be much
more smoother great so hope you
understand and in the comment box you
have to let me know that what is the
tick and what is the frames and in one
frames how many tick can be perform in
one tick what are the things happen
basically State synchronization happen
physics simulation or input transition
or computational logic anything happen
between the client server or host client
okay great okay so now we have
understand the tick part now it's come
to the how we can apply on the player so
basically we have to create one more
script that is the player so just open
this script remove this part and make
sure that you have the fusion so using
Fusion we are not going to use mono
behavor because it is getting movement
from the host in every tick so what we
have to use Network Behavior so we are
going to use Network behavior for
movement what we need we need Network
character controller and in awake
basically we have to access this one so
just do the tab and basically what we
want so we want every tick on every TI
we want to access the host input host
input what we need we have to override
update Network so basically fix update
Network call on every tick okay means
when game Loop complete
one that is the tick and in every tick
so basically we get the input and then
we do the movement locally and then that
structure input we send to the host and
that host just sync my state on another
device on network like write the logic
and basically this is the tick so I have
already explained to you that in one
frame tick can be called okay so in
every we are getting call means in one
frame this method will be called
multiple time basically we have to get
we have to get the input from the host
so basically we have to get get input so
basically we have to out network data so
that thing network network input data we
have to get input from the host so out
Network input you can call data and that
data we have to do in the if we are
getting get input then basically we are
getting this structure from the network
the data and that data we have to get
direction so we we have to get the
direction and then we have to normalize
okay and after the normalize what we
want we want movement so basically we
have to access the character controller
Dot and then we have to perform the
movement so basically we use move and
let's see we want to move 10 unit and
then in the direction so that is the
data Direction multiply by time do Delta
so basically in unity we multiply by
time. Delta but it is getting from the
network so we have to use Runner do
Delta time that's it so basically it
will be called in every and I will
explain about tick what is the tick host
you can call host or you can call server
here script we have to assign on the
player so just go on the player and here
we have to search that is the player
okay so now you can see that we have
assigned the player and it's showing
like this and let's run let's see how it
working to play and basically we have
tested with the multiplayer So currently
I'm doing in my local don't worry about
it test with the the multiplayer I'm
just joining to the host so click on the
host now we have generated our player
let's see it's getting movement or not
so this is my player so here you can see
we are able to move our player right so
this is the beauty of fusion and we are
able to move our player so you can just
t on the network so it will work
perfectly so we are able to move our
player system is getting hacked so I'm
running so many software right now
that's it for today tutorial and hope
you enjoy the video hope you learn
something you and just run on the
multiplayer you can check and thanks for
watching have a good day see you in next
video bye-bye take
care
Ver Más Videos Relacionados
Collision Detection - How to Make a 2D Game in Java #6
How To Make a Topdown RPG in Godot 4: Adding The Player (Part 1)
What are the main Assumptions of Linear Regression? | Top 5 Assumptions of Linear Regression
useRef: como funciona esse React Hook | #AluraMais
Juiced Up First Person Character Controller Tutorial - Godot 3D FPS
Variable amount pricing in Stripe Checkout
5.0 / 5 (0 votes)