Unity Multiplayer Tutorial using Mirror [ABANDONED]
Vložit
- čas přidán 5. 08. 2024
- I'VE ABANDONED THIS SERIES AS I DON'T USE UNITY ANYMORE. AN UNREAL ENGINE VERSION OF THIS TUTORIAL WILL BE RELEASED SOON.
Welcome to my video series on how to make a multiplayer game with Unity using Mirror
Join The Discord : / discord
PlayerController Script : ghostbin.co/paste/herv9
If you like this, please check out some of my other videos. Thanks for watching! - Věda a technologie
I saw photon, i looked at a comment about mirror. I searched mirror and saw that my favourite channel already made a tutorial 28 minutes ago. Thats a miracle.
Thank you :)
a miracle? that magic
I saw mirror, I looked at a comment about photon, and want zyapguy to make a vid :)
and this is da comment
Same
Multiplayer using mirror
Step 1. Get mirror, use Amazon because honestly you’re not gonna leave you’re home
Step 2. Hang mirror on wall
Step 3. Go insane (30 minutes of debugging C in text edit with no google should do this (or 30 seconds of JavaScript)
Step 4. Stand in front of a mirror and hallucinate that you’re reflection comes alive
Step 5. Multiplayer!
Great vid man. Helped me a lot. Can’t wait to see this tutorial continued!
bro this is the only unity mirror tutorial i resonated with. really bummed me out when i saw that this was the only tutorial you made though :(
Yeah really sad.
I came to this channel for the "types of programmers" kind of video, didn't expect any tutorials, but ngl this is a pretty good one.
Good job!
The problem is, I don't want to keep making the same type of video. Also, someone asked me to make a multiplayer tutorial so I decided why not. But worry not! I will still make types of videos :D
@@zyapguy Understandable, like your videos either way
@@spook2387 Thank you :D
@@zyapguy soooo ep 2 when lmao
@@zyapguy will you continue this ? please
Hey man, this video is wayyy wayyy way more valuable to me to learn Mirror. Huge thumbs to you!
Clear tutoria! Awesome! Thanks! I hope you keep with the good content my friend!
Bro, this gonna be really good
Great intro video! Hoping you're going to continue the series soon!
Good to see fresh Unity tutorials!
When I was learning Mirror, there was like only 2 tutorials and one of them didn't even work. Wanted to help the community out :D
@@zyapguy playercontrolerscript pastebin link does not work anymore
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(CharacterController))]
public class PlayerController: MonoBehaviour
{
public float walkingSpeed = 7.5f;
public float runningSpeed = 11.5f;
public float jumpSpeed = 8.0f;
public float gravity = 20.0f;
public Camera playerCamera;
public float lookSpeed = 2.0f;
public float lookXLimit = 45.0f;
CharacterController characterController;
Vector3 moveDirection = Vector3.zero;
float rotationX = 0;
[HideInInspector]
public bool canMove = true;
void Start()
{
characterController = GetComponent();
// Lock cursor
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
void Update()
{
// We are grounded, so recalculate move direction based on axes
Vector3 forward = transform.TransformDirection(Vector3.forward);
Vector3 right = transform.TransformDirection(Vector3.right);
// Press Left Shift to run
bool isRunning = Input.GetKey(KeyCode.LeftShift);
float curSpeedX = canMove ? (isRunning ? runningSpeed : walkingSpeed) * Input.GetAxis("Vertical") : 0;
float curSpeedY = canMove ? (isRunning ? runningSpeed : walkingSpeed) * Input.GetAxis("Horizontal") : 0;
float movementDirectionY = moveDirection.y;
moveDirection = (forward * curSpeedX) + (right * curSpeedY);
if (Input.GetButton("Jump") && canMove && characterController.isGrounded)
{
moveDirection.y = jumpSpeed;
}
else
{
moveDirection.y = movementDirectionY;
}
// Apply gravity. Gravity is multiplied by deltaTime twice (once here, and once below
// when the moveDirection is multiplied by deltaTime). This is because gravity should be applied
// as an acceleration (ms^-2)
if (!characterController.isGrounded)
{
moveDirection.y -= gravity * Time.deltaTime;
}
// Move the controller
characterController.Move(moveDirection * Time.deltaTime);
// Player and Camera rotation
if (canMove)
{
rotationX += -Input.GetAxis("Mouse Y") * lookSpeed;
rotationX = Mathf.Clamp(rotationX, -lookXLimit, lookXLimit);
playerCamera.transform.localRotation = Quaternion.Euler(rotationX, 0, 0);
transform.rotation *= Quaternion.Euler(0, Input.GetAxis("Mouse X") * lookSpeed, 0);
}
}
}
thats the real code
THX YOU
MAD LAD
+1.000.000 social credits
thanks but i already typed it manually before i even see this :'
I’m pretty new to unity especially multiplayer, this will help a lot. Thx
This is really cool! I always wanted to learn something about game development.
Also *types of unity developers* when?
Happy to see new types of video 👍👍
Hope you enjoyed it!
thank you this video was realy useful, you deserve more subs
Thank you so much! I was stuck on mirror for so long
You are slowly (but surely) becoming an Indian guy on CZcams...
no shit
Why Indian guy? Can't understand it... he is Russian I think and this video is sooooooo good.
@@tukang3d There is a saying circulating between all programmers (now including you) that has been present since the beginning of the programmer era and goes like this: "If you can't find it on StackOverflow, there must be an Indian guy on CZcams explaining it to you in one of his videos".
take it as a joke (because you are able to find almost everything on StackOverflow these days), but if you ever encounter a computer problem, you can pretty much be sure, that some Indian CZcams channel explains it.
@@jenycek2222 yeap agree.. hmm.. but I mostly hate Indian channel especially when I see the video title in English but when I play the video he talks Hindi. Dang it.
This is the best tutorial on mirror in youtube
This was a very good tutorial. Good job 👍
Gotta love youtubers doing "part 1" of something and not continuing the work.
MAN , YOU ARE THE BEST , I COULDN’T FOUND HOW FIX A CAMERA’S PROBLEM . AND I FINALLY I FOUND , MY MASTER TO FIX IT 😅
Thank you. I'm Korean but this video was so good that I could understand all of things.
It's important to note that you CAN have 2 cameras active at the same time :) I use 4 for my project at all times. It will make 1/the most recently turned-on camera for the main projection. You can change which one is used in the code or by enabling/disabling. You can also use a secondary camera for a MiniMap or as a second screen if you want a second monitor screen activated. Oddly enough it is very handy to have that as an option. I highly recommend trying out secondary or more monitor options for games as it could make a game that much more customizable for those with the tech/want. I'm a huge fan of having as many options as I could get. Think observation duty but you could monitor 2 ROOMS AT ONCE!!! Now that sounds like a really interesting effect. Just wish it would work better for streamers/CZcamsrs. I'm still trying to figure that part out lol.
Please continue the series!
This is helpful. Thanks a million!
U lucky boy, youtube recommended you to me. Not a big fan of mirror, I like use litenetlib + custom netcode, but nice vid, wish you luck with your tutorial series
your video is awesome, please continue the part
Great tutorial! Keep going!
Hello, I'm creating an FPS camera and using the FirstPersonController script from Unity's StandardAssets, it works almost perfectly, however, do you know why when I activate the vertical mouse clamp, on mobile it keeps giving a nan nan nan problem on the camera? When I disable the clamp, the error disappears, however, the clamp is gone. Thank you!
you handled both my errors! new sub for you!
Lol, I thought you only make a programmer meme or somewhat, but actually more helping me make a multiplayer game, Thank god, that I subscribe to your channel. I actually didn't understand about it
Thanks for watching :D
@@zyapguy 😊👍 itu was helpful
Great tutorial man :)
thanks, you've earned new subscriber :)
Continue this series!!
First of all I don't recommend connection with IP address so i would suggest 2 things. First, mirror has a room manager transport so, check out the documentation about this transport.
Second, Mirror suggests to checkout there unity demo scene about that transport to learn about it.
HELLO! As I understand it, the mirror is only for a local connection? Have you tried connecting to other computers?
The link in description for the code is not working for some reason, is it just me?
Actual tutorial yeah boi
Is this online or only LAN? I dont want to buy a Server ho can i make that the player hosts a server, i mean peer to peer
Please make more videos on Unity Multiplayer with Mirror.. Please
Thanks in advance... And I Subscribed. :)
very useful for me. tks a lot
Assets\Mirror\Runtime\NetworkReaderExtensions.cs(157,17): error CS0246: The type or namespace name 'ReadOnlySpan' could not be found (are you missing a using directive or an assembly reference?)
I install it and got these error, any idea to fix it
OMG You helped me so much
I already know how to make multiplayer games in unity. But still watched the hole video.
whole*
it does not work, once i join i can see the other instnace move thye are both singleplayer all that happens is that a capsule spawns and gets removed once the other one leaves/joines, help
Thank you 😍😍😍 awesome 🤩🤩🤩
There was no active transport when calling NetworkServer.Listen, If you are calling Listen manually then make sure to set 'Transport.active' first
UnityEngine.Debug:Assert (bool,string)
NullReferenceException: Object reference not set to an instance of an object
how do I fix this?????????? i did the sam as shown in the video:(
can you please make a video about how to do the same thing without "client authority" in the client "network transform" ? i've been waiting for a second tutorial in this series..
so IP address + open port, if the server is running on that then anyone can connect?
I got an error NullReferenceException: Object reference not set to an instance of an object
Thanks a lot
Hello. I am currently working on a multiplayer FPS game but ran into a problem. What should I do to make the player's mesh invisible to the player controlling it?
I'm sure you've sorted it by now, but if not you could disable the mesh renderer component if isLocalPlayer is true
If local player disable ur player's mesh xD it's ez what's the problem
I write the ip address of the server, but the client does not want to connect to the server what to do?
Waiting for Part 2
Very helpful! Pls come back to life
uhh how do how does other players from internet?
He breifs over it too much and the UI is different from his
Help
Can this achieve animation synchronization?
Yes of course. In the player, add the NetworkAnimator. drag the animator that you want to sync to the empty slot and check "Client". After that, it will sync perfectly.
any follow up tutorials soon ?
Hello! And can you Please 🙏show how to make a connection if it's a different type of game (board game) When it's not control of a character, but moving objects with the cursor is just like any board game!
i really just need one thing, how df do i make a debug.log from a client on another client >:,c
we found the youtuber programmer! lol
i want to be a bird
How did I miss this
Where is PART2?
Why am I watching this
Am i like oh boy time to code on my nonexistent PC
For Anyone Who Is getting trouble with the code in ghostbin here's it right here: using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(CharacterController))]
public class PlayerController : MonoBehaviour
{
public float walkingSpeed = 7.5f;
public float runningSpeed = 11.5f;
public float jumpSpeed = 8.0f;
public float gravity = 20.0f;
public Camera playerCamera;
public float lookSpeed = 2.0f;
public float lookXLimit = 45.0f;
CharacterController characterController;
Vector3 moveDirection = Vector3.zero;
float rotationX = 0;
[HideInInspector]
public bool canMove = true;
void Start()
{
characterController = GetComponent();
// Lock cursor
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
void Update()
{
// We are grounded, so recalculate move direction based on axes
Vector3 forward = transform.TransformDirection(Vector3.forward);
Vector3 right = transform.TransformDirection(Vector3.right);
// Press Left Shift to run
bool isRunning = Input.GetKey(KeyCode.LeftShift);
float curSpeedX = canMove ? (isRunning ? runningSpeed : walkingSpeed) * Input.GetAxis("Vertical") : 0;
float curSpeedY = canMove ? (isRunning ? runningSpeed : walkingSpeed) * Input.GetAxis("Horizontal") : 0;
float movementDirectionY = moveDirection.y;
moveDirection = (forward * curSpeedX) + (right * curSpeedY);
if (Input.GetButton("Jump") && canMove && characterController.isGrounded)
{
moveDirection.y = jumpSpeed;
}
else
{
moveDirection.y = movementDirectionY;
}
// Apply gravity. Gravity is multiplied by deltaTime twice (once here, and once below
// when the moveDirection is multiplied by deltaTime). This is because gravity should be applied
// as an acceleration (ms^-2)
if (!characterController.isGrounded)
{
moveDirection.y -= gravity * Time.deltaTime;
}
// Move the controller
characterController.Move(moveDirection * Time.deltaTime);
// Player and Camera rotation
if (canMove)
{
rotationX += -Input.GetAxis("Mouse Y") * lookSpeed;
rotationX = Mathf.Clamp(rotationX, -lookXLimit, lookXLimit);
playerCamera.transform.localRotation = Quaternion.Euler(rotationX, 0, 0);
transform.rotation *= Quaternion.Euler(0, Input.GetAxis("Mouse X") * lookSpeed, 0);
}
}
}
Server Authority video please! :D
pls make a new part
when i clicked on this video
it had 69 views
lol
its 13k views now
the ghostbin doesn't work..
Could you add another way to get the PlayerController Script?
it says bad gate way
@@fakemayham084 yeah that’s what I mean
Shiiit amazing tutorial but where is part2 :(
Why only one part :(
the player controller script link isn't working. can you send me a pastebin or something please?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(CharacterController))]
public class PlayerController: MonoBehaviour
{
public float walkingSpeed = 7.5f;
public float runningSpeed = 11.5f;
public float jumpSpeed = 8.0f;
public float gravity = 20.0f;
public Camera playerCamera;
public float lookSpeed = 2.0f;
public float lookXLimit = 45.0f;
CharacterController characterController;
Vector3 moveDirection = Vector3.zero;
float rotationX = 0;
[HideInInspector]
public bool canMove = true;
void Start()
{
characterController = GetComponent();
// Lock cursor
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
void Update()
{
// We are grounded, so recalculate move direction based on axes
Vector3 forward = transform.TransformDirection(Vector3.forward);
Vector3 right = transform.TransformDirection(Vector3.right);
// Press Left Shift to run
bool isRunning = Input.GetKey(KeyCode.LeftShift);
float curSpeedX = canMove ? (isRunning ? runningSpeed : walkingSpeed) * Input.GetAxis("Vertical") : 0;
float curSpeedY = canMove ? (isRunning ? runningSpeed : walkingSpeed) * Input.GetAxis("Horizontal") : 0;
float movementDirectionY = moveDirection.y;
moveDirection = (forward * curSpeedX) + (right * curSpeedY);
if (Input.GetButton("Jump") && canMove && characterController.isGrounded)
{
moveDirection.y = jumpSpeed;
}
else
{
moveDirection.y = movementDirectionY;
}
// Apply gravity. Gravity is multiplied by deltaTime twice (once here, and once below
// when the moveDirection is multiplied by deltaTime). This is because gravity should be applied
// as an acceleration (ms^-2)
if (!characterController.isGrounded)
{
moveDirection.y -= gravity * Time.deltaTime;
}
// Move the controller
characterController.Move(moveDirection * Time.deltaTime);
// Player and Camera rotation
if (canMove)
{
rotationX += -Input.GetAxis("Mouse Y") * lookSpeed;
rotationX = Mathf.Clamp(rotationX, -lookXLimit, lookXLimit);
playerCamera.transform.localRotation = Quaternion.Euler(rotationX, 0, 0);
transform.rotation *= Quaternion.Euler(0, Input.GetAxis("Mouse X") * lookSpeed, 0);
}
}
}
error !! Object reference not set to an instance of an object
How did u open 2 instances at 6:02
I built the game and just opened 2 of them
bro how do you connect with people in mirror
Hey can you write the script in the comment? (because the link dont work)
Was there a part 2?
Are you going to make a part 2?
Player controller script link not working ;(
just add your own player script, it doesnt have to be his, and if you do dont forget to add "using Mirror;", "if(!isLocalPlayer) { return;}", and change "MonoBehaviour" to "NetworkBehaviour"
Hello, where is the part 2?
When next part xD?
how did you opened 2 unity games at once?
Ctrl (command for laptop) + shift + B then click add open scenes then build and run
Next tutorial when :D
👍
I'm starting to question If miking squid game by making a "game" about it is even worth it now. 😅
does this work with webgl?
It will if you use the transport called WebSockets Transport. Learn more here :mirror-networking.gitbook.io/docs/transports/websockets-transport
if anyone has an issue that the address is already is in use like me, use port 5555 or similar
may u sand my the code pls i cant open the link
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(CharacterController))]
public class PlayerController: MonoBehaviour
{
public float walkingSpeed = 7.5f;
public float runningSpeed = 11.5f;
public float jumpSpeed = 8.0f;
public float gravity = 20.0f;
public Camera playerCamera;
public float lookSpeed = 2.0f;
public float lookXLimit = 45.0f;
CharacterController characterController;
Vector3 moveDirection = Vector3.zero;
float rotationX = 0;
[HideInInspector]
public bool canMove = true;
void Start()
{
characterController = GetComponent();
// Lock cursor
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
void Update()
{
// We are grounded, so recalculate move direction based on axes
Vector3 forward = transform.TransformDirection(Vector3.forward);
Vector3 right = transform.TransformDirection(Vector3.right);
// Press Left Shift to run
bool isRunning = Input.GetKey(KeyCode.LeftShift);
float curSpeedX = canMove ? (isRunning ? runningSpeed : walkingSpeed) * Input.GetAxis("Vertical") : 0;
float curSpeedY = canMove ? (isRunning ? runningSpeed : walkingSpeed) * Input.GetAxis("Horizontal") : 0;
float movementDirectionY = moveDirection.y;
moveDirection = (forward * curSpeedX) + (right * curSpeedY);
if (Input.GetButton("Jump") && canMove && characterController.isGrounded)
{
moveDirection.y = jumpSpeed;
}
else
{
moveDirection.y = movementDirectionY;
}
// Apply gravity. Gravity is multiplied by deltaTime twice (once here, and once below
// when the moveDirection is multiplied by deltaTime). This is because gravity should be applied
// as an acceleration (ms^-2)
if (!characterController.isGrounded)
{
moveDirection.y -= gravity * Time.deltaTime;
}
// Move the controller
characterController.Move(moveDirection * Time.deltaTime);
// Player and Camera rotation
if (canMove)
{
rotationX += -Input.GetAxis("Mouse Y") * lookSpeed;
rotationX = Mathf.Clamp(rotationX, -lookXLimit, lookXLimit);
playerCamera.transform.localRotation = Quaternion.Euler(rotationX, 0, 0);
transform.rotation *= Quaternion.Euler(0, Input.GetAxis("Mouse X") * lookSpeed, 0);
}
}
}
still waiting for part 2
Sir part 2 where ?
Part 2 ??
This looks suspiciously easy
the websever is offline :(
sağol knk
I was the first 12:21 minutes of the video like: "mhh... is this a real tutorial or a troll?"
hey big brain can u tell us how to make movement with the new input system in package manager plzzzzz
I will try to do that sometime soon, thanks for the suggestion
@@zyapguy im currently making a multiplayer game and u by diong this tuto i will love it
thx for responding
@@zyapguy u good youtuber not like dani boi
the playercontroller script page isn't working anymore
just add your own player script, it doesnt have to be his, and if you do dont forget to add "using Mirror;", "if(!isLocalPlayer) { return;}", and change "MonoBehaviour" to "NetworkBehaviour"
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(CharacterController))]
public class PlayerController: MonoBehaviour
{
public float walkingSpeed = 7.5f;
public float runningSpeed = 11.5f;
public float jumpSpeed = 8.0f;
public float gravity = 20.0f;
public Camera playerCamera;
public float lookSpeed = 2.0f;
public float lookXLimit = 45.0f;
CharacterController characterController;
Vector3 moveDirection = Vector3.zero;
float rotationX = 0;
[HideInInspector]
public bool canMove = true;
void Start()
{
characterController = GetComponent();
// Lock cursor
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
void Update()
{
// We are grounded, so recalculate move direction based on axes
Vector3 forward = transform.TransformDirection(Vector3.forward);
Vector3 right = transform.TransformDirection(Vector3.right);
// Press Left Shift to run
bool isRunning = Input.GetKey(KeyCode.LeftShift);
float curSpeedX = canMove ? (isRunning ? runningSpeed : walkingSpeed) * Input.GetAxis("Vertical") : 0;
float curSpeedY = canMove ? (isRunning ? runningSpeed : walkingSpeed) * Input.GetAxis("Horizontal") : 0;
float movementDirectionY = moveDirection.y;
moveDirection = (forward * curSpeedX) + (right * curSpeedY);
if (Input.GetButton("Jump") && canMove && characterController.isGrounded)
{
moveDirection.y = jumpSpeed;
}
else
{
moveDirection.y = movementDirectionY;
}
// Apply gravity. Gravity is multiplied by deltaTime twice (once here, and once below
// when the moveDirection is multiplied by deltaTime). This is because gravity should be applied
// as an acceleration (ms^-2)
if (!characterController.isGrounded)
{
moveDirection.y -= gravity * Time.deltaTime;
}
// Move the controller
characterController.Move(moveDirection * Time.deltaTime);
// Player and Camera rotation
if (canMove)
{
rotationX += -Input.GetAxis("Mouse Y") * lookSpeed;
rotationX = Mathf.Clamp(rotationX, -lookXLimit, lookXLimit);
playerCamera.transform.localRotation = Quaternion.Euler(rotationX, 0, 0);
transform.rotation *= Quaternion.Euler(0, Input.GetAxis("Mouse X") * lookSpeed, 0);
}
}
}
Plz make a part 2
Zyapguy
Sir , i need your help , i hope this comment comes to your sight..
I am having problems with spawning my player , when i click HOST (server+client) , it throws null reference exception mirror.networkserver.addtransporthandlers()
How to fix this , please help me