Reader small image

You're reading from  Build Your Own Metaverse with Unity

Product typeBook
Published inSep 2023
PublisherPackt
ISBN-139781837631735
Edition1st Edition
Tools
Concepts
Right arrow
Author (1)
David Cantón Nadales
David Cantón Nadales
author image
David Cantón Nadales

David Cantón Nadales, software engineer from Seville, Spain, with more than 15 years of experience. He is currently a Technical Leader at Grupo Viajes El Corte Inglés, a leading travel company in Europe. He has done a multitude of projects and video games with Unity, VR/AR with Oculus, Hololens, HTC Vive, DayDream and LeapMotion. He was ambassador of the Samsung community "Samsung Dev Spain", and organizer of "Google Developers Group Sevilla". He led more than 100 projects throughout his career. As a social entrepreneur stands out Grita, a social network that emerged during the confinement of COVID-19 that allowed to talk to other people and help each other psychologically. In 2022 he won the Top Developers Awards organized by Samsung.
Read more about David Cantón Nadales

Right arrow

Turning Our World into a Multiplayer Room

Metaverse and multiplayer are definitions that often go hand in hand; it is hard to imagine a single-player metaverse. One of the most fun features a virtual world can have is for it to interact with other players in real time, and for those users to interact with friends and other users in different scenarios and activities.

In this chapter, we will focus on adding this feature to our project. We will achieve this with Photon SDK, a powerful framework that offers easy integration for our Unity3D projects. We will learn how to send the movements and animations through the network so that all the users of our metaverse are synchronized in real time.

Photon offers an SDK for integrating text chat and voice chat into our project, with all the services being under the same provider. This is one of the reasons why I chose Photon for this book. We will see this in Chapter 10, Adding Text and a Voice Chat to the Room.

We will cover the following...

Technical requirements

This chapter does not require any special technical requirements, but we will start programming scripts in C#. Therefore, it’s advised that you have basic notions of this programming language.

We need an internet connection to browse and download an asset from the Unity Asset Store. We will continue using the project we created during Chapter 1, Getting Started with Unity and Firebase. Remember that we have this book’s GitHub repository, which contains the complete project that we will work on here: https://github.com/PacktPublishing/Build-Your-Own-Metaverse-with-Unity/tree/main/UnityProject.

You can also find the complete code for this chapter on GitHub at: https://github.com/PacktPublishing/Build-Your-Own-Metaverse-with-Unity/tree/main/Chapter09

Getting started with Photon SDK

Photon SDK is a set of tools and services for developing networked games in Unity3D. Photon SDK allows you to create real-time multiplayer games, including online, cooperative and competitive games.

Photon SDK offers a scalable and reliable networking solution that allows you to create multiplayer online games with low latencies and a large number of concurrent players. Some of the features and benefits of Photon SDK include the following:

  • Real-time connection: Photon SDK enables the creation of real-time, online games, which means players can interact in real time without any lag.
  • Ease of use: Photon SDK provides an easy-to-use interface that simplifies the creation of multiplayer games. It also provides detailed documentation and technical support to help you integrate Photon SDK into your Unity project.
  • Scalability: Photon SDK is capable of handling a large number of simultaneous players, making it ideal for massively multiplayer...

Synchronizing movements and animations in the network

After downloading and configuring Photon SDK, we will move on to the more technical part of this chapter. Throughout the following pages, we will learn how to connect the tools offered by this SDK to provide multiplayer technology to our project. You will be surprised how easy Photon makes this.

Photon offers a series of ready-made scripts that we only have to attach to the Prefab that represents the player. That is to say, all the ugly parts of programming such as synchronizing movements and animations are done for us, so we only have to know how to integrate them. That’s what we will deal with in this chapter.

Preparing the player Prefab

Before we start, we must consider the details. Photon SDK will now be in charge of the scene changes and instantiating the player in the scene. So, for it to be able to perform these actions, the Prefabs that are going to be instantiated in the scene must be in a path under the...

Testing synchronization with another user

Testing a local multiplayer game is a tedious and complicated task. We need to replicate a local development environment that allows at least two players to connect so that they can test our code.

One of the options that comes to mind is to create a build of our project and run it on other computers, or even launch it on our computer and then launch the project in the Unity editor to test two players.

But this would be terrible – we would have to compile for every test we do and, if our code fails, we would have to create a new build for each fix. Fortunately, a team of developers have developed a tool that will change our lives called ParrelSync.

Introducing ParrelSync

ParrelSync is an extension for the Unity editor that allows users to test a multiplayer game without building the project by having another Unity editor window open and reflecting the changes of the original project.

In short, ParrelSync will create a copy...

Summary

Throughout this chapter, we learned all about Photon and we created a new project in the Dashboard area. We also learned how to convert our single-player metaverse into a spectacular multiplayer metaverse. With Photon SDK, we managed to easily add new scripts that can synchronize all the players, along with their animations and movements, on the network.

We also learned how to change scenes and have them transmitted to the network to see how users appear and disappear from our scene when we change rooms in Photon.

In the next chapter, we will learn how to integrate two new services offered by Photon – Photon Chat and Photon Voice. With these services, we will add voice chat and text chat features to our metaverse.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Build Your Own Metaverse with Unity
Published in: Sep 2023Publisher: PacktISBN-13: 9781837631735
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at ₹800/month. Cancel anytime

Author (1)

author image
David Cantón Nadales

David Cantón Nadales, software engineer from Seville, Spain, with more than 15 years of experience. He is currently a Technical Leader at Grupo Viajes El Corte Inglés, a leading travel company in Europe. He has done a multitude of projects and video games with Unity, VR/AR with Oculus, Hololens, HTC Vive, DayDream and LeapMotion. He was ambassador of the Samsung community "Samsung Dev Spain", and organizer of "Google Developers Group Sevilla". He led more than 100 projects throughout his career. As a social entrepreneur stands out Grita, a social network that emerged during the confinement of COVID-19 that allowed to talk to other people and help each other psychologically. In 2022 he won the Top Developers Awards organized by Samsung.
Read more about David Cantón Nadales