Make YOUR OWN Multiplayer FPS (2023 - Unity, Photon PUN 2)
HTML-код
- Опубликовано: 20 июн 2024
- DOWNLOAD PACK & MOUSE LOOK SCRIPT
drive.google.com/file/d/1j-92...
OR AS A ZIP FILE
drive.google.com/file/d/1mv2Y...
▶︎ Links
Photon PUN 2 on the asset store:
assetstore.unity.com/packages...
Photon Dashboard:
dashboard.photonengine.com/
Try out the game that I'm teaching you to make! (steam: bit.ly/3urlRUJ)
▶︎ Description
Howdy everyone! I’ve decided to make a brand new series on how to make your own networked multiplayer FPS game in Unity. This is based on my own Steam game.
In this tutorial, we're setting up Photon PUN 2, making our multiplayer room manager script and syncing some player bean movement over the network.
▶︎ Social Media:
Discord: / discord
Twitter: / _bananadev
▶︎ Similar Videos:
How We Remade CSGO in 7 Days | Multiplayer | Unity | Steam - • How We Remade CSGO in ...
MAKING YOUR FIRST FPS in Unity with FPS Microgame! - • MAKING YOUR FIRST FPS ...
▶︎ Timestamps:
(0:00) - Intro
(0:15) - Creating Project
(0:37) - Setting up Server
(2:10) - Room Manager Script
(5:36) - Setting up our Player
(6:10) - Player Movement
(11:53) - Making it First Person!
(13:00) - Syncing players over the network
(15:00) - Testing & outro
▶︎ About Me:
I'm bananadev and I'm an indie game dev! I make tutorials and devlogs about how to make games in Unity.
Thanks a lot for watching 💜
#madewithunity #indiedev #devlog
The mouse look script is here :)
drive.google.com/file/d/1j-92b6X5cLxszYKdZb_BAyJx0xuxhVmA/view?usp=sharing
Couldn't you at least show on Video the script? I just wanted to see how you did it and now I must download the scripts 🙁
can u make the RoomManager im having trouble with it
plz
@@decode_script
@@arnaudloche2725bro where did u get the scripts im not able to get that too
Help needed NullReferanceException: Object reference not set to an instance of an object
SO HELPFUL, Definitely underrated channel
Using the Resources folder is creating a tech dept for the future. Use addressables.
Thanks
Im currently using riptide for my fps, i may check photon later, your channel seems to be awesome nice production quality excited to see nore of you
Awesome, thank you!
open the nore
@@epic_piggyninja1668 lol
@@epic_piggyninja1668 not funny
@@fakemayham084 your not funny
dude this is gonna be awsome ooooo
you bet bro
ok honestly, I do not feel rdy yet to make my own mutliplayer game, but damn I will still watch your vids.
:)
yooo good as alway
I hope this tutorial continues because this helps me a lot...
Oh it certainly will! got a lot planned :)
@@bananastutorials nice
same
Continue this tutorial broo its awesome :)))
pt.2 dropping today!🤙
underrated channel dude
thank you bro
you basically just made a free course and only have 1.3k subs. Bro deserves better 🥺🥺
Who else is watching this now
Hii !! Your video is amazing and i want to ask that if i use Character Controller instead of Rigibody then what Photon view should i use ???
you got any idea on how I can make each player have its own camera in unity multiplayer?
Question. I used another script to allow scoping in for my sniper. wanted to change the sense but when i tried to change the sense in the script by grabing the component and setting that = new vector2 (1, 1) instead it didnt work. how should i get the sense to slow down?
Wow, thanks dude! Awesome tutorial. Can I use PUN for the mobile?
Yes you can!
cool video)
Love these tutorials but the RoomManager code has errors for me in Microsoft visuals and i was wonder what you are using for the code and how i may download it?
At 04:45, how do you actually get those black boxes?
Hiya, new game dev here! I'm trying to make a competitive third person mobile game and I was wondering if I should go for PUN 2 or Fusion 2. Which one would work best in my case?
jetbrains user... instant subscribe
Hey @bananastutorials i love the vid so far but am wondering if you know to to fix my problem?
when i added the mouse look script it doesnt let me look up or down. Thanks!
Try this new script, maybe your camera is rotated wrong?
drive.google.com/file/d/1j-92b6X5cLxszYKdZb_BAyJx0xuxhVmA/view?usp=sharing
When i try to type Vector3 CalculateMovement(float _speed) it gives me a error saying not all code paths return a value
do you know how to fix it?
continue the code it will get fixed by itself
can i use my own movment script?
Hi, This has been very helpful so far, but I was wondering if I could just put the player in a prefab folder? Thanks alot by the way!
You cant because Photon wont recognize it as a object that wants to be synced.
@@calok Ik, I just found out a few weeks ago. Thank you anyway!
@@MUSKETPENGUIN3000 someone else might also stumble on this issue and see replies :)
@@calok yep, that's nice :)
Actually, sorry for the late response, but you can set a path for it in the script itself.@@MUSKETPENGUIN3000
you forgot to show how to add the onjoinedroom thing
you're getting like 50 subs per day now :))
yessir 🙌
Where do i get the wallpaper you have on your PC??
The Mouse Look Script is not contained in the in the pack nor is anything else. What happened???
Thanks for letting me know!
Posted it here:
drive.google.com/file/d/1j-92b6X5cLxszYKdZb_BAyJx0xuxhVmA/view?usp=sharing
Hello, i tried to launch the game, and the camera started to fall underneath the plane? (if that makes sense). I need help
you probably put your rigidbody on top of the camera, make sure its on the bean (player) and if you still fall trough the ground make sure that there's a collider on the floor and maybe put your player a little higher above the ground
Thanks for the video! I keep getting this error:
Can not Instantiate before the client joined/created a room. State: Joining
Should the Instantiation be in another method? Or maybe it is trying to Instantiate too quickly - before the client joined/created a room?
Actually, I just fixed this by looking at some forums. I added the Instantiate to the OnJoinedRoom() method instead of the OnJoinedLobby as you had it in the video. Why won't mine work the way yours works though?
public override void OnJoinedRoom()
{
base.OnJoinedRoom();
GameObject _player = PhotonNetwork.Instantiate(player.name, spawnPoint.position, Quaternion.identity);
}
Awesome thanks for sharing!!
@@AaronAsherRandall i got the same error and tried your code and i dont spawn in can you help me pls?
@@gamedevguy54 same
@@gamedevguy54 same
Hi
We need another link for your packages, the one that is in the description doesn't have anything in it
Thanks for letting me know!
Posted it here:
drive.google.com/file/d/1j-92b6X5cLxszYKdZb_BAyJx0xuxhVmA/view?usp=sharing
My Visual Studio never changes the color of the Photon related code and then whenever i reopen my project it askes me if i want to open in safe mode and gives me tons or errors. if i delete the room manager script it clears all the errors can i please have help
You provably have an error, check the console window for errors :)
how do you get it to autofill photon commands?
I'm getting the error : "JoinOrCreateRoom failed. Client is on MasterServer (must be Master Server for matchmaking)but not ready for operations (State: Joining). Wait for callback: OnJoinedLobby or OnConnectedToMaster.
UnityEngine.Debug:LogError (object)".
When I click play it seems like it runs fine but I also get an error in the console.
Maybe wait a bit before pressing the join button
void Start()
{
Debug.Log("Connecting");
PhotonNetwork.ConnectUsingSettings();
}
public override void OnConnectedToMaster()
{
base.OnConnectedToMaster();
Debug.Log("Connected to Server");
PhotonNetwork.JoinLobby();
}
public override void OnJoinedLobby()
{
base.OnJoinedLobby();
PhotonNetwork.JoinOrCreateRoom("test", null, null);
Debug.Log("We are in the Lobby");
}
public override void OnJoinedRoom()
{
base.OnJoinedRoom();
Debug.Log("We are connected and in a room");
GameObject _player = PhotonNetwork.Instantiate(player.name, spawnPoint.position, Quaternion.identity);
_player.GetComponent().IsLocalPlayer();
}
i cant make the room manager script
tthere are issues
hey man thanks for the tutorials! I am still learning the ropes with programming and I keep on getting this error (Can not Instantiate before the client joined/created a room. State: Joining UnityEngine.Debug Joining Engine.Debug Joining
UnityEngine.Debug:LogError (object))
which is preventing me from spawning my player. any help would be greatly appreciated. Thanks
i guess your trying to instantiate a prefab in the network while joining a room, try doing a while loop after the join room function thats something like while(!PhotonNetwork.InRoom) but make it empty, its gonna run the rest of the code if your gonna be in a room. after the while loop add the instantiate method. (idk i really dont use the tut, it may work tho!)
why does the player deletes itself few seconds later in play mode
plz fix me this Error Can not Instantiate before the client joined/created a room. State: Joining
I am Having an error that Multiple precompiled assemblies with the same name websocket-sharp. Dll included oon the current platform. Only one assembly with the same name is allowed per platform.
Reimport into another project, see if that helps
@@bananastutorialsit says join lobby not called because client is not connected or not ready yet
@@bananastutorialsnvm thanks
So new to this, how do you pull up that script editor for the room manager script?
visual studio
@bananadev2 i dont have all the assembly csharp things in my visual studios idk what to do
How do you autofill Photon Commands?
It says it, "Can not Instantiate before the client joined/created a room state: joining" what does this mean it wont let me join the room or anything how do I fix this?
Hey Alex, I'm CodeMaster Muhammad Hosny, nice to meet you.
Nice to meet you too!
When i build the game, i go into unity and my pc build. If i move one character, the other one moves as well.
try enabling the movement script for player only when player is instantiated
Hi, I'm a beginner and I just got acquainted with this environment and I don't know how to code message: I will use what you use. If possible, please introduce any source that can help me❤❤❤❤❤😮
Hello, how to enable those "black boxes" in the code editor and it will show the data types and variables when you type a certain code.
Rider program, or Rider Extension for Visual Studio
Hey there! I'm developing a multiplayer soccer game using PUN2 and Unity. Currently, I can create rooms, allow players to join and leave rooms, and as the room host, I can start the game and send all players to the 'game' screen. Additionally, all players can walk, run, and jump, and everyone can see these actions. However, there's an issue: Since it's a soccer game, I've added a 'ball' object in the middle of the field, and within my PlayerController script, I'm using OnCollisionEnter to apply strong contact to the ball, thus altering its position-a basic soccer mechanic. My 'ball' object includes components like Sphere Collider, Rigidbody, Photon View, Photon Transform View, and Photon Rigidbody View. While other players can interact with the ball smoothly, the host of the room cannot see other players changing the ball's position; the ball only moves when the host touches it, and then other players can see its movement. How can I resolve this? Thanks!
Code:
using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
[SerializeField] float mouseSensitivity, sprintSpeed, walkSpeed, jumpForce, smoothTime;
[SerializeField] GameObject cameraHolder;
float verticalLookRotation;
bool grounded;
Vector3 smoothMoveVelocity;
Vector3 moveAmount;
Rigidbody rb;
PhotonView pv;
private void Awake()
{
rb = GetComponent();
pv = GetComponent();
}
private void Start()
{
if (!pv.IsMine)
{
Destroy(GetComponentInChildren().gameObject);
Destroy(rb);
}
}
private void Update()
{
if (!pv.IsMine)
return;
PlayerLook();
PlayerMove();
PlayerJump();
}
private void PlayerLook()
{
transform.Rotate(Vector3.up * Input.GetAxisRaw("Mouse X") * mouseSensitivity);
verticalLookRotation += Input.GetAxisRaw("Mouse Y") * mouseSensitivity;
verticalLookRotation = Mathf.Clamp(verticalLookRotation, -90f, 90f);
cameraHolder.transform.localEulerAngles = Vector3.left * verticalLookRotation;
}
void PlayerMove()
{
Vector3 moveDir = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")).normalized;
moveAmount = Vector3.SmoothDamp(moveAmount, moveDir * (Input.GetKey(KeyCode.LeftShift) ? sprintSpeed : walkSpeed), ref smoothMoveVelocity, smoothTime);
}
void PlayerJump()
{
if (Input.GetKeyDown(KeyCode.Space) && grounded)
{
rb.AddForce(transform.up * jumpForce);
}
}
public void SetGroundState(bool _grounded)
{
grounded = _grounded;
}
private void FixedUpdate()
{
if (!pv.IsMine)
return;
rb.MovePosition(rb.position + transform.TransformDirection(moveAmount) * Time.fixedDeltaTime);
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Ball"))
{
Rigidbody ballRb = collision.gameObject.GetComponent();
if (ballRb != null)
{
ballRb.AddForce(transform.forward * 1f, ForceMode.Impulse);
}
}
}
}
Can not Instantiate before the client joined/created a room. State: Joining
UnityEngine.Debug:LogError (object)
same i dont know how to fix it
Hey, man, realy like your tutorials, thanks for sharing :) But if you could send a link to the entire project, it would greatly simplify the learning process ) Can you send, please ? :)
thats not learning bro
Voice is noisey, please have a good mic. Difficult to understand your voice properly. I am your new subscriber
When I made the spawnpoint it doesn't work, it says can not instaniate before client joined/created a room and stops the game pls help me
i have a same problem
From where can i find the mouse look script ?
Posted it here:
drive.google.com/file/d/1j-92b6X5cLxszYKdZb_BAyJx0xuxhVmA/view?usp=sharing
So I got everything working, and I am experiencing a lot of jitter and lag. Was wondering if there was anything I could do to make the connection super smooth.
Note: I am using the free version and am not sure if that would have any affect.
In your rigidbody settings on the player, set the interpolation dropdown to interpolate :)
@@bananastutorials I did it but its not working
Is it compatible with webgl build?
Help please, I have a big problem "Operation JoinLobby (229) not called, client state: ConnectingToMasterServer error. Help😢
hey man, it’s hard to tell with the little info I have, make sure to copy my room manager code exactly tho
The error "Operation JoinLobby (229) not called, client state: ConnectingToMasterServer" suggests that the JoinLobby operation is not being called, and the client state is still in the process of connecting to the master server.
Double-check your code to ensure that the JoinLobby operation is being called correctly. Look for any potential issues such as incorrect method calls, missing callbacks, or improper timing of the JoinLobby operation.
void Start()
{
Debug.Log("Connecting");
PhotonNetwork.ConnectUsingSettings();
}
public override void OnConnectedToMaster()
{
base.OnConnectedToMaster();
Debug.Log("Connected to Server");
PhotonNetwork.JoinLobby();
}
public override void OnJoinedLobby()
{
base.OnJoinedLobby();
PhotonNetwork.JoinOrCreateRoom("test", null, null);
Debug.Log("We are in the Lobby");
}
public override void OnJoinedRoom()
{
base.OnJoinedRoom();
Debug.Log("We are connected and in a room");
GameObject _player = PhotonNetwork.Instantiate(player.name, spawnPoint.position, Quaternion.identity);
_player.GetComponent().IsLocalPlayer();
}
The RoomManager script is not working pls help or link the roommanager code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class RoomManager : MonoBehaviourPunCallbacks
{
// Start is called before the first frame update
void Start()
{
Debug.Log("Connecting...");
PhotonNetwork.ConnectUsingSettings();
}
public override void OnConnectedToMaster()
{
base.OnConnectedToMaster();
Debug.Log("Connected to Server");
PhotonNetwork.JoinLobby();
}
public override void OnJoinedLobby()
{
base.OnJoinedLobby();
PhotonNetwork.JoinOrCreateRoom("test", null, null);
Debug.Log("We're connected and in a room now");
}
}
can you post all scripts in the comments?
It says Vector 3, Vector2, Rigidbody, and MonoBehaviour can not be found, how could I fix this?
I think you’re not deriving from monobehavour or you deleted some of the using statements at the top of your script
Thank you very much, first of all, I went through the whole process step by step, but I don't understand why I get this error.
Can not Instantiate before the client joined/created a room. State: PeerCreated
UnityEngine.Debug:LogError (object)
I hope you can help me
Hey i had the same error and here is the fixed version : (Thank me later :D)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class RoomManager : MonoBehaviourPunCallbacks
{
public GameObject player;
public Transform spawnPoint;
// Start is called before the first frame update
void Start()
{
Debug.Log("Connecting...");
PhotonNetwork.ConnectUsingSettings();
}
public override void OnConnectedToMaster()
{
base.OnConnectedToMaster();
Debug.Log("Connected to Server");
PhotonNetwork.JoinLobby();
}
public override void OnJoinedLobby()
{
base.OnJoinedLobby();
PhotonNetwork.JoinOrCreateRoom("test", null, null);
Debug.Log("We're connected and in a room now");
}
public override void OnJoinedRoom()
{
base.OnJoinedRoom();
Debug.Log("Joined a room");
GameObject _player = PhotonNetwork.Instantiate(player.name, spawnPoint.position, Quaternion.identity);
}
}
@@tegbx3619 Thank i love you
thank i had the same error
@@tegbx3619
@@tegbx3619 you are the real hero in my heart
@@tegbx3619 thx so much bro
I get 3 errors:
1) 'Vector2' is an ambiguous reference between 'UnityEngine.Vector2' and 'System.Numerics.Vector2'
2) 'Vector3' is an ambiguous reference between 'UnityEngine.Vector3' and 'System.Numerics.Vector3'
3) 'Input' is an ambiguous reference between 'UnityEngine.Input' and 'UnityEngine.Windows.Input'
Please how do I resolve these?
Hi,
You import this library System.Numerics when you code. Be careful to use only Vector2 from UnityEngine.
To resolve your problem, delete the "using System.Numerics" on the top.
My movement has no counter movement and i just slip off my plane. I have already finished eps 2. I was wondering if you can help
?
uhhh never mind i just used a different movement and it’s okay!👌
I have the room manager script copied 1 to 1 and mine doesnt work and doesn't tell me what is wrong is it because i use visual studio or what
Nevermind I opened it wrong
i couldnt write the code correct
i followed your steps but couldnt make it same
like if your line is 17 mine would be 12 or 13
can you please give the whole code as a zip or googledrive
please
doesn't matter on what line the code is, just needs to be correct
does someone have the movement script?
Hey when i hit play my player isnt spawning but i dont get any errors except
Can not Instantiate before the client joined/created a room. State: Joining
UnityEngine.Debug:LogError (object)
Same
void Start()
{
Debug.Log("Connecting");
PhotonNetwork.ConnectUsingSettings();
}
public override void OnConnectedToMaster()
{
base.OnConnectedToMaster();
Debug.Log("Connected to Server");
PhotonNetwork.JoinLobby();
}
public override void OnJoinedLobby()
{
base.OnJoinedLobby();
PhotonNetwork.JoinOrCreateRoom("test", null, null);
Debug.Log("We are in the Lobby");
}
public override void OnJoinedRoom()
{
base.OnJoinedRoom();
Debug.Log("We are connected and in a room");
GameObject _player = PhotonNetwork.Instantiate(player.name, spawnPoint.position, Quaternion.identity);
_player.GetComponent().IsLocalPlayer();
}
Can not Instantiate before the client joined/created a room. State: Joining
it says that it can only spawn the player after it connected to the server, make sure you put the instantiate line in the roommanager on the correctline. so check your script and see if everything is the same
My Mouse Look Thing Is Allowing Me To Look Down Or Up Only Left Or Right
Is it still for 2024
can you please add copy and paste on the script
How about photon fusion?
Pun is much simpler and its what I use for my game with 300K + downloads, fusion is good but a lot more work, might make a tutorial on it in a couple months
in light of recent events u better remove that text at 0:07 XD 200k installs
A , D, W, and S keys are flipped. Please help.
Maybe you have a negative sign somewhere in your movement script
make more unity tutorials
How do you get the scripting part?
visual studio
pls tell me what software your useing
unity
@@Comprobrain i mean coding software
Could you share the script for the Room Manager?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class RoomManager : MonoBehaviourPunCallbacks
{
public GameObject player;
public Transform spawnPoint; // The player's respawn point
void Start()
{
Debug.Log("Connecting...");
PhotonNetwork.ConnectUsingSettings();
}
public override void OnConnectedToMaster()
{
base.OnConnectedToMaster();
Debug.Log("Connected to the server");
PhotonNetwork.JoinLobby();
}
public override void OnJoinedLobby()
{
base.OnJoinedLobby();
Debug.Log("Joined the lobby");
// Attempt to join or create a room named "test"
PhotonNetwork.JoinOrCreateRoom("test", null, null);
// Debug.Log("We've joined a room");
// GameObject _player = PhotonNetwork.Instantiate(player.name, spawnPoint.position, Quaternion.identity);
}
public override void OnJoinedRoom()
{
base.OnJoinedRoom();
Debug.Log("Joined the room");
// Ensure this call is made when the client is the master client of the room
if (PhotonNetwork.IsMasterClient)
{
// Instantiate the player object
GameObject _player = PhotonNetwork.Instantiate(player.name, spawnPoint.position, Quaternion.identity);
}
}
}
by a random person in comments
Can you use just any movement script?
yes
@@JoskeVR yeah figur3d that out 2 months ago
Movement not working
hi, I need Source Code PLZ
whenever i test out the player movement, I move in both the x and z axis at the same time (when I press w or s).
Never mind, I got it to work. All I did was change the walk speed from 4 to 5, and back to 4.
it says "Can not Instantiate before the client joined/created a room" on console how can i fix it
make sure the room manager script is exactly how i’ve done it :)
that’s where it’s from best of luck
@@bananastutorials i tried it several times but the errror is not solved
@@lixq7r here is ep 1 just change what has to be changed if eny thing ( using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class RoomManager : MonoBehaviourPunCallbacks
{
// Start is called before the first frame update
void Start()
{
Debug.Log(message:"[Connectomg....") ;
PhotonNetwork.ConnectUsingSettings();
}
// Update is called once per frame
void Update()
{
}
public override void OnConnectedToMaster()
{
base.OnConnectedToMaster();
Debug.Log(message: "Connected to Server");
PhotonNetwork.JoinLobby();
}
public override void OnJoinedLobby()
{
base.OnJoinedLobby();
PhotonNetwork.JoinOrCreateRoom(roomName: "test", roomOptions: null, typedLobby: null);
Debug.Log(message: "Were connected and in a room now");
}
}
@@bananastutorials I have got everything set up exactly as you and I am getting the same error...
Could you put the movement in the Comments Im Having Trouble
I Got it
It keeps saying
NullReferenceExeption: Object reference not set to an instance of an object
How do I fix this please
something is not referenced in the inspector
Is anyone else getting the error “All compiler errors have to be fixed before you can enter play mode”?
Edit: This is when setting up the Room Manager Script, I haven’t even started on the rest of the video.
bro i can give u a new script if u want. it works
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveMents : MonoBehaviour
{
private CharacterController controller;
private Vector3 playerVelocity;
private bool groundedPlayer;
private float playerSpeed = 2.0f;
private float jumpHeight = 1.0f;
private float gravityValue = -9.81f;
private void Start()
{
controller = gameObject.AddComponent();
}
void Update()
{
groundedPlayer = controller.isGrounded;
if (groundedPlayer && playerVelocity.y < 0)
{
playerVelocity.y = 0f;
}
Vector3 move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
controller.Move(move * Time.deltaTime * playerSpeed);
if (move != Vector3.zero)
{
gameObject.transform.forward = move;
}
// Changes the height position of the player..
if (Input.GetButtonDown("Jump") && groundedPlayer)
{
playerVelocity.y += Mathf.Sqrt(jumpHeight * -3.0f * gravityValue);
}
playerVelocity.y += gravityValue * Time.deltaTime;
controller.Move(playerVelocity * Time.deltaTime);
}
}
@@graphicsxoff Thanks
Resources
script
ples
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
public float walkSpeed = 4f;
public float maxVelocityChange = 10f;
private Vector2 input;
private Rigidbody rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent();
}
// Update is called once per frame
void Update()
{
input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
input.Normalize();
}
void FixedUpdate()
{
rb.AddForce(CalculateMovement(walkSpeed), ForceMode.VelocityChange);
}
Vector3 CalculateMovement(float _speed)
{
Vector3 targetVelocity = new Vector3(input.x, 0, input.y);
targetVelocity = transform.TransformDirection(targetVelocity);
targetVelocity *= _speed;
Vector3 velocity = rb.velocity;
if (input.magnitude > 0.5f)
{
Vector3 velocityChange = targetVelocity - velocity;
velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
velocityChange.x = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
velocityChange.y = 0;
return (velocityChange);
}
else
{
return new Vector3();
}
}
}
code pls
you are so lazy
lol very small pack
can you give the projetc or code
It'll take a few weeks for me to finish this series. & then I'll release the final project
I'd recommend you follow along though so you actually get the chance to learn the skills and can add new features to your game :)
@@bananastutorials will it free
@@cinarbugra omg lol just type it out its not hard not everthing in life is free if he wanted to make it 10 bux he could if he makes it free its hes choice.........😂
There is a small error that I cannot solve:
When I delete the "Player" and try to start the "game" I get this error:
"Cannot be made immediately before the client has joined/created a room. Status: Joining UnityEngine.Debug:LogError (object)"
and:
"Can not Instantiate before the client joined/created a room. State: Joining
UnityEngine.Debug:LogError (object)
Photon.Pun.PhotonNetwork:Instantiate (string,UnityEngine.Vector3,UnityEngine.Quaternion,byte,object[]) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetwork.cs:2477)
RoomManager:OnJoinedLobby () (at Assets/RoomManager.cs:38)
Photon.Realtime.LobbyCallbacksContainer:OnJoinedLobby () (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:4455)
Photon.Realtime.LoadBalancingClient:OnOperationResponse (ExitGames.Client.Photon.OperationResponse) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2944)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback (ExitGames.Client.Photon.StreamBuffer) (at D:/Dev/photon-sdk-dotnet/PhotonDotNet/PeerBase.cs:877)
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands () (at D:/Dev/photon-sdk-dotnet/PhotonDotNet/EnetPeer.cs:577)
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands () (at D:/Dev/photon-sdk-dotnet/PhotonDotNet/PhotonPeer.cs:1777)
Photon.Pun.PhotonHandler:Dispatch () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:232)
Photon.Pun.PhotonHandler:FixedUpdate() (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:152)"
Both Player and Spawn Point are set in RoomManager.
All log's link: drive.google.com/drive/folders/1PFJDolQU74QU3W_Ljd65OnxgSF-zNi_E?usp=sharing
Just wait a bit longer before clicking the join buttons, I might make a video addressing it specifically soon
I keep getting this error
Error CS0029 Cannot implicitly convert type 'float' to 'UnityEngine.Vector3' Assembly-CSharp D:\Multiplayer FPS\Assets\Movement.cs 45 Active
here is my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
public float walkSpeed = 4f;
public float maxVelocityChange = 10f;
private Vector2 input;
private Rigidbody rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent();
}
// Update is called once per frame
void Update()
{
input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
input.Normalize();
}
private void FixedUpdate()
{
rb.AddForce(CalculateMovement(walkSpeed), ForceMode.VelocityChange);
}
Vector3 CalculateMovement(float _speed)
{
Vector3 targetVelocity = new Vector3(input.x, 0, input.y);
targetVelocity = transform.TransformDirection(targetVelocity);
targetVelocity *= _speed;
Vector3 velocity = rb.velocity;
if (input.magnitude > 0.5f)
{
Vector3 velocityChange = targetVelocity - velocity;
velocityChange = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
velocityChange = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
velocityChange.y = 0;
return (velocityChange);
}
else
{
return new Vector3();
}
}
}
someone please help me
New fixed lines
velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
The error "Operation JoinLobby (229) not called, client state: ConnectingToMasterServer" suggests that the JoinLobby operation is not being called, and the client state is still in the process of connecting to the master server.
Double-check your code to ensure that the JoinLobby operation is being called correctly. Look for any potential issues such as incorrect method calls, missing callbacks, or improper timing of the JoinLobby operation.
Thanks, I missed that part.
HELP! I get this error Can not Instantiate before the client joined/created a room. State: Joining
UnityEngine.Debug:LogError (object)
Photon.Pun.PhotonNetwork:Instantiate (string,UnityEngine.Vector3,UnityEngine.Quaternion,byte,object[]) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetwork.cs:2477)
RoomManager:OnJoinedLobby () (at Assets/Scripts/RoomManager.cs:31)
Photon.Realtime.LobbyCallbacksContainer:OnJoinedLobby () (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:4455)
Photon.Realtime.LoadBalancingClient:OnOperationResponse (ExitGames.Client.Photon.OperationResponse) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2944)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback (ExitGames.Client.Photon.StreamBuffer) (at D:/Dev/photon-sdk-dotnet/PhotonDotNet/PeerBase.cs:877)
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands () (at D:/Dev/photon-sdk-dotnet/PhotonDotNet/EnetPeer.cs:577)
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands () (at D:/Dev/photon-sdk-dotnet/PhotonDotNet/PhotonPeer.cs:1777)
Photon.Pun.PhotonHandler:Dispatch () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:232)
Photon.Pun.PhotonHandler:FixedUpdate () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:152)
I also get this error, but I select it.
You can look this!
Possible Issues:
Instantiating the player object within the OnJoinedLobby method might be premature, as at this point the client has only entered the lobby and has not yet joined or created a specific game room.
The call to PhotonNetwork.Instantiate may occur before the client successfully joins a room.
Solution:
Move the instantiation code to the correct callback: You should instantiate the player object within the OnJoinedRoom or OnCreatedRoom callback methods. These methods are invoked after the client has successfully joined or created a room.
Modify the script: Move the instantiation code from OnJoinedLobby to OnJoinedRoom or OnCreatedRoom.
Here is an example of the modified RoomManager script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class RoomManager : MonoBehaviourPunCallbacks
{
public GameObject player;
public Transform spawnPoint; // The player's respawn point
void Start()
{
Debug.Log("Connecting...");
PhotonNetwork.ConnectUsingSettings();
}
public override void OnConnectedToMaster()
{
base.OnConnectedToMaster();
Debug.Log("Connected to the server");
PhotonNetwork.JoinLobby();
}
public override void OnJoinedLobby()
{
base.OnJoinedLobby();
Debug.Log("Joined the lobby");
// Attempt to join or create a room named "test"
PhotonNetwork.JoinOrCreateRoom("test", null, null);
// Debug.Log("We've joined a room");
// GameObject _player = PhotonNetwork.Instantiate(player.name, spawnPoint.position, Quaternion.identity);
}
public override void OnJoinedRoom()
{
base.OnJoinedRoom();
Debug.Log("Joined the room");
// Ensure this call is made when the client is the master client of the room
if (PhotonNetwork.IsMasterClient)
{
// Instantiate the player object
GameObject _player = PhotonNetwork.Instantiate(player.name, spawnPoint.position, Quaternion.identity);
}
}
}
Please note the following points:
Ensure that the player object is set up to be network-instantiable and is marked as such in the Photon Network project view.
The spawnPoint should be a common point in the room for all players to share, or you need to have logic to determine a specific spawn point for each player.
Make sure the PhotonView component on the player object has a unique view ID that is not zero. With these changes, you should be able to correctly instantiate the player object after the client successfully joins or creates a room.
@@yewenysupreme Thanks very much it works
drive.google.com/file/d/1KumgQyqcYDcZGuWJS8gdw7BpzHcHlAn-/view
for those saying the link for his FPS pack doesnt work
OMg thanks a lot :D
thanks a lot bro