RPC in FPS with Photon PUN 2 in Unity (Part 10)



How to make a Multiplayer Video Game

Discord:

For this tutorial lesson, on how to make a multiplayer game in Unity using the Photon 2 plugin we will be using the RPC functions we have learned about to make a basic first-person shooter control that will sync across the network. This tutorial will teach you how to use the RPC function of the Photon 2 plugin in other scenarios. After this lesson, you should have a better understanding of RPC function and what they can do as well when to use them. You will also learn how to take any game machinic and make it work in a multiplayer game.

SUBSCRIBE for regular Video Game making videos:

We will begin by creating variables in our Avatar setup script for the first one will be player health and the next one will be player damage. We will then create a new C# script called Avatar Combat. In this script, we will create some new variables. We will then initialize these variables. We will then create a shooting function and we will use Raycast to do this. We first want to check for player input and then we will create our Raycast. If the Raycast hit another player then we want to remove health from that player. We will then save our C# script and go back to Unity.

In Unity, we will create and add a new camera to our player avatar object. We then need to attach our new scripts to their respective object and set the variables.

We will then go back to our Avatar combat script and we will turn this script into a script that will work across the network. We will do this by creating an RPC function that will synchronize the player’s health across the network when the player has been shot.

If you followed along with the video then you should now have a working basic FPS controller that networks the player’s health when shot.

Nguồn: https://uwallpaperhd.com/

Xem thêm bài viết khác: https://uwallpaperhd.com/game/

37 Comments

  • Leo Menz

    12:40 just for me 😀

    June 22, 2020 - 9:04 am Reply
  • Diogo Garcia

    thank you!!

    June 22, 2020 - 9:04 am Reply
  • GAMEMODE MAN818 GMM HD

    Thanks for the tutorial took me a while to get and I get really annoyed when it keeps on saying things like "Object not set to an instance of an object" and stuff like that. Cheers

    June 22, 2020 - 9:04 am Reply
  • Ruben H.

    Great series man love it

    June 22, 2020 - 9:04 am Reply
  • Music Rock

    helped me alot.

    June 22, 2020 - 9:04 am Reply
  • I I

    Could be nice to see mobile touch input for Multiplayer game as well. You are the best what I have seen for Unity Multiplayer explanation.!!!

    June 22, 2020 - 9:04 am Reply
  • I I

    @Info gamer – can you do simple characters inventory replication and weapon PICK -up and DROP-down scripts for Photon PUN 2? Could be nice to see another scripts like player Death and player random respawn in maps random spawn points.

    June 22, 2020 - 9:04 am Reply
  • bao hua

    Hi. I want to spawn origin objects for one match. For example: When i created a match and spawned 20 objects, so all players in match see the same 20 objects. How can i do that? Thank a lot.

    June 22, 2020 - 9:04 am Reply
  • Veevslav1

    Awesome Tutorials series.

    June 22, 2020 - 9:04 am Reply
  • ChrisVernerStudio

    Hi, great tutorials! I'm having an issue where my character's Character controller is never grounded on the terrain (isGrounded is never true). I'm going nuts with this. When I add a RigidBody to it it flies up in the air when I rotate him???? Do you know how to fix this?

    June 22, 2020 - 9:04 am Reply
  • bi jian Wu

    Tank you. your video is excellent, but why there just few people watch it.

    June 22, 2020 - 9:04 am Reply
  • shreyas rajapurkar

    This particular video just seals the deal for me. The way you emphasize on concept explanation rather than just writing code and creating a game just makes the whole series amazing.

    June 22, 2020 - 9:04 am Reply
  • Maybe Raj

    (When we spawn in multiplayer scean) Is it possible that we first check if player is mine and if yes then only add components like camera, controller, etc..?

    June 22, 2020 - 9:04 am Reply
  • JARAWS TNAMAS

    why dont u give a link to the scripts man it woul be sooo easier and faster

    June 22, 2020 - 9:04 am Reply
  • Tom Norc

    hi great tutorials I've managed to get a multiplayer room working in a way shorter amount of time than expected, however in i cannot get the client to change its health numbers, the damage is happening i can see it in the editor and the text is set to 100 on start, the editor main client changes when hit though,
    edit; Forgot to put on the Photontransform for my RayCastPoint, i've been making a third person game instead so had to have the ray shoot from in front of the player so i didn't hit myself , whoops,

    June 22, 2020 - 9:04 am Reply
  • Zack Youells

    thnk you so much man

    June 22, 2020 - 9:04 am Reply
  • K君 harekelas

    Your videos deserve more attentions!

    June 22, 2020 - 9:04 am Reply
  • Mohamed Muflahi

    I'm stuck on the end how did you attach the health text to the prefab?

    June 22, 2020 - 9:04 am Reply
  • CrisPleys In Valorant

    when create multiplayerSettings script? what part?

    June 22, 2020 - 9:04 am Reply
  • RomanBanana

    If I were to instantiate a bullet within RPC_shooting would it be using PhotonNetwork.instantiate or just instantiate?

    June 22, 2020 - 9:04 am Reply
  • The Box

    For some reason in my editor the health updates when I am shot from the standalone, but when I am shot from the editor the standalone's health doesn't update. In unity the local health for the standalone is updated and in the standalone the health is set to 100 at start.

    June 22, 2020 - 9:04 am Reply
  • shieldgenerator7

    Debug.DrawLine() has a time parameter. If you set it greater than 0, it will keep that line drawn for that many seconds.

    June 22, 2020 - 9:04 am Reply
  • c0nstancy

    Thank you for these videos. I will say, you reorganize that desk to your right behind you a lot 😛 One video I see a bookcase on it, another without, then another with! haha

    June 22, 2020 - 9:04 am Reply
  • Royce Fernandes

    Hello Everyone, I want to rotate the Avatar's 'rightarm' using 'T' button I want the same to be synchronized across the network. Could someone please help me out with that.

    June 22, 2020 - 9:04 am Reply
  • Leandro Amarillo

    Hey! great videos, they are a lot of help. I have one question about that RPC_Shooting method, is it really ok to tell every client cast rays for the same thing? Could there be an edge case where the rays hits in some clients but no in others? Does it solves those conflicts taking the masters results as truth?. Other way could be making the raycast locally and sending the results, but if the client shooting has lag he might be using old information to make the calculation and still cause a suboptimal online experience.

    June 22, 2020 - 9:04 am Reply
  • David

    Hello! If someone uses Cheatengine or some other programs, could they modify values ​​like playerHealth and playerDamage? What is the best way to store variable values ​​to avoid their external modification?

    June 22, 2020 - 9:04 am Reply
  • Jean-Marc Priest

    +++

    June 22, 2020 - 9:04 am Reply
  • Lethn

    You deserve way more likes and views for doing these tutorials, I'm so glad to get up to date PUN tutorials!

    Just as a note for people with recent versions of PUN, for some reason the "RpcTarget.All" function doesn't exist that he uses. I checked the autocorrect as I typed and it turns out there's a whole section called PhotonTargets.All and this seems to be the right piece of code but could somebody confirm? The description matches what he's talking about but I wanted to double check.

    June 22, 2020 - 9:04 am Reply
  • IfDef EndIf

    12:42 Clear…worked for me with the point and click script..Great job

    June 22, 2020 - 9:04 am Reply
  • Mert Kırımgeri

    Do you think calling the rpc in everyframe is a good way of shooting ? Because as long as I know, photon has a certain limit of calls per second such as 500 (I guess). So, I am thinking about calling rpc just at the very beginning and the very end of shooting sequence. This can be done with an OnMouseDown check with changing a boolean to true. That way all the clients will shoot locally and they only broadcast what they started and finished, we also see they are shooting besides we dont use a lot of rpc calls as well.

    June 22, 2020 - 9:04 am Reply
  • Børge Skram

    What about making a video showing how to kill a player and make it respawn?

    June 22, 2020 - 9:04 am Reply
  • Сергей Колючкин

    Thank you very much for awesome guides! I just wanna say ".CompareTag(tag)" is more efficient than " == tag"

    June 22, 2020 - 9:04 am Reply
  • Børge Skram

    Hi! Thanks for the great tutorials. How would you script the camera if it was a sideview multiplayer platform game ?(like this video, just in multiplayer: https://www.youtube.com/watch?v=MFQhpwc6cKE).

    June 22, 2020 - 9:04 am Reply
  • Afit

    Hey, looking for a unity photon developer. Reply to me if interested.

    June 22, 2020 - 9:04 am Reply
  • Colin

    Your content is extremely underrated sir

    June 22, 2020 - 9:04 am Reply
  • Shubham Potdukhe

    Great! Thanks for this lesson.
    Sir I am trying to make a turn based game between two players using photon.
    Sir,Please arrange a lesson for a Turn Based Game using photon..There is very few information on turn based game in photon..

    June 22, 2020 - 9:04 am Reply
  • Mian Sufyan

    Hey, Nice Tutorial thanks a lot! and yes i have a question too. When i build and play the game in 2 stand alone windows they both work fine but with a stand alone and editor they both create their own rooms instead of joining the existing one?

    June 22, 2020 - 9:04 am Reply

Leave A Comment

Your email address will not be published.