I have a player with a chest obtained in Start() and pointed towards a "target" cube I move up and down to simulate aiming. I am trying to send the direction of the chest over the network so the players can see the upward or downward direction the character is aiming. Is there a decently optimized way to send the "bending" of the spine over the network.
Public class PlayerMove : MonoBehaviourPun, IPunObservable{
public Transform chest;
void Start()
{
chest = animator.GetBoneTransform(HumanBodyBones.Chest);
}
void LateUpdate()
{
Camera.main.transform.LookAt(target.transform.position);
chest.LookAt(target.transform.position);
chest.rotation = chest.rotation * Quaternion.Euler(offset);
}
//Some camera movement stuff and unimportant, unrelated code below.
}
public class NetworkPlayer : MonoBehaviourPun, IPunObservable {
protected Vector3 realPosition = Vector3.zero;
protected Quaternion realRotation = Quaternion.identity;
private void Awake()
{
animator = GetComponentInChildren();
}
public void Update()
{
if (this.photonView.IsMine)
{
}
else
{
transform.position = Vector3.Lerp(transform.position, realPosition, 0.1f);
transform.rotation = Quaternion.Lerp(transform.rotation, realRotation, 0.1f);
}
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting)
{
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
stream.SendNext(animator.GetFloat("Speed"));
stream.SendNext(animator.GetBool("IsGrounded"));
stream.SendNext(animator.GetFloat("JoyStickX"));
stream.SendNext(animator.GetFloat("JoyStickY"));
stream.SendNext(animator.GetFloat("AimAngle"));
}
else
{
realPosition = (Vector3)stream.ReceiveNext();
realRotation = (Quaternion)stream.ReceiveNext();
animator.SetFloat("Speed",(float)stream.ReceiveNext());
animator.SetBool("IsGrounded",(bool)stream.ReceiveNext());
animator.SetFloat("JoyStickX",(float)stream.ReceiveNext());
animator.SetFloat("JoyStickY",(float)stream.ReceiveNext());
animator.SetFloat("AimAngle",(float)stream.ReceiveNext());
}
}
}
I've tried following all tutorials related to "Bone" & "sync" issues with Photon and even tried using RPC's but I cannot get the rotation of the upper body/chest to propagate over the network no matter what. Please if you can help I'd appreciate it!
↧
How to sync chest LookAt() across network
↧
ReSpawn Dead Player at different location in same room.
How can I re spawn dead player at other location in same room without causing issues?
1. Should I firsts destroy the Photon Instantiated prefab and then again follow same procedure that I followed when I instantiated all players while creating and joining room?
OR
2. Should I deactivate all the meshed of game object and re position it and enable it again giving others a feel of death and re spawn?
Any help would be appreciated. Thanks
↧
↧
Pun Classic over LAN?
Hello
Is it possible to use PUN Classic over a LAN without any internet access? I couldn't find a definite answer on the forums
↧
Can Photon cause a gameobject to get disabled?
- I am seeing some very strange behavior in Unity. When I join a room, sometimes one of the gameobjects with a Punbehaviour attached gets disabled. This only happens when I join an existing room (and that too not always) but never when I create a room.
- I have checked my code thoroughly using breakpoints and debug logs and I am sure that my code is not disabling that gameobject.
- Is there any precedence of Photon showing this kind of behavior, i.e. disabling gameobjects?
- Just to give an idea of the setup: I have two punbehaviors in the scene attached to two different gameobjects.
- Both of them are subscribed to some of the usual Photon callbacks like OnJoinedRoom, OnPhotonPlayerConnected etc. Could this be causing the problem?
- I am using PUN 1.0 and Unity 2018.3.0
I can change the architecture to work with just one Punbehaviour and see if that fixes the problem but it's going to take significant effort. If anybody can confirm encountering this kind of bug before then I would feel a lot better changing up the architecture.
Thanks.
↧
void OnRoomListUpdate(List roomList) works just sometimes
Hey guys im troubling pretty much with this new function in pun 2. I dont know why they just left GetRoomList in it was so much easier to use. But anyway so i have my project and i recently switched over to pun 2 because of the things that were made better. I pretty much changed everything in my project so that it runs on pun 2 and so I also changed GetRoomList to OnRoomListUpdate() but now when i run my game on two devices and create one room on my first device and then try to join the room just shows up sometimes in my server list and i dont know what i did wrong.
Code:
public override void OnRoomListUpdate(List roomList)
{
InstancePosition = StartInstancePosition;
foreach (GameObject destroy in GameObject.FindGameObjectsWithTag("Room"))
{
Destroy(destroy.gameObject);
}
foreach (RoomInfo Room in roomList)
{
GameObject Instance = Instantiate(RoomUI, Vector2.zero, Quaternion.identity) as GameObject;
Instance.transform.SetParent(gameObject.transform, false);
InstancePosition = new Vector3(InstancePosition.x, InstancePosition.y + 42, InstancePosition.z);
Instance.GetComponent().anchoredPosition = new Vector3(0, InstancePosition.y, 0);
Instance.transform.GetChild(0).gameObject.GetComponent().text = Room.Name;
if (Room.Name.Contains("_password"))
{
Instance.gameObject.GetComponent().Tag = Room.Name.ToString();
string PasswordName = Room.Name.ToString().Replace("_password", "");
Instance.transform.GetChild(0).gameObject.GetComponent().text = PasswordName.Replace(PasswordName.Substring(0, 5), "");
Instance.transform.GetChild(1).gameObject.SetActive(true);
}
else
{
Instance.gameObject.GetComponent().Tag = Room.Name.ToString();
Instance.transform.GetChild(1).gameObject.SetActive(false);
}
}
}
↧
↧
PlayerCount, Peers and Connections Actives do no match
Hi there,
We are analyzing disconnect issues on our On-Premise server. We are monitoring some game and lobby stats on the client side and some counters on the server side.
Here are the numbers from Windows Performance Monitor that we are trying to make sense of:
1) Photon server is running, no client connected:
-Peers: 2
-Connections Active: 1
2) First client connects to the lobby:
-Peers:3
-Connections Active: 2
3) First client creates and joins a room:
-Peers: 4
-Connections Active: 3
4) Second client joins the lobby:
-Peers:5
-Connections Active: 4
5) Second client joins the room:
-Peers:6
-Connections Active:5
We are using PUN and PUN Voice. We would like to know how the Peers and the Connection Active counters are calculated.
It looks like Peers=(2*PlayerCount)+2 and Connections Active = (2*PlayerCount)+1
Does each Voice instance count as an extra Peer/Connection on top of each PUN player? We just want to make sure that we don't instantiate extra players by accident.
Many thanks!
↧
Photon destroy the network instantiate
good evening, from a few days I have a bug in my game, quickly, I shoot, the bullet should appear in all the instances of the game, but instead of creating the bullet in the other customer, the other customer sees destroyed the another player "the one who shot" and after a few seconds the server disconnects for both. I also wanted to tell you that the only information exchanged between customers is the position of the two players. The error that appears in the consol is this: Network destroy Instantiated GO: projectile (Clone)
UnityEngine.Debug: Log (Object)
Photon.Pun.PhotonNetwork: RemoveInstantiatedGO (GameObject, Boolean) (at Assets / Photon / PhotonUnityNetworking / Code / PhotonNetworkPart.cs: 712)
Photon.Pun.PhotonNetwork: LocalCleanupAnythingInstantiated (Boolean) (at Assets / Photon / PhotonUnityNetworking / Code / PhotonNetworkPart.cs: 265)
Photon.Pun.PhotonNetwork: LeftRoomCleanup () (at Assets / Photon / PhotonUnityNetworking / Code / PhotonNetworkPart.cs: 235)
Photon.Pun. <> C: <. Cctor> b__122_0 (ClientState, ClientState) (at Assets / Photon / PhotonUnityNetworking / Code / PhotonNetwork.cs: 990)
Photon.Realtime.LoadBalancingClient: set_State (ClientState) (at Assets / Photon / PhotonRealtime / Code / LoadBalancingClient.cs: 355)
Photon.Realtime.LoadBalancingClient: OnStatusChanged (StatusCode) (at Assets / Photon / PhotonRealtime / Code / LoadBalancingClient.cs: 2578)
ExitGames.Client.Photon. <> C__DisplayClass105_0: b__0 () (at C: /Dev/photon-sdk-dotnet/PhotonDotnet/PeerBase.cs: 907)
ExitGames.Client.Photon.EnetPeer: DispatchIncomingCommands () (at C: /Dev/photon-sdk-dotnet/PhotonDotnet/EnetPeer.cs: 435)
ExitGames.Client.Photon.PhotonPeer: DispatchIncomingCommands () (at C: /Dev/photon-sdk-dotnet/PhotonDotnet/PhotonPeer.cs: 1548)
Photon.Pun.PhotonHandler: Dispatch () (at Assets / Photon / PhotonUnityNetworking / Code / PhotonHandler.cs: 193)
Photon.Pun.PhotonHandler: FixedUpdate () (at Assets / Photon / PhotonUnityNetworking / Code / PhotonHandler.cs: 127).
↧
Unity Photon Transform View Issues
Hi, so I'm fairly new to using Photon Networking and multiplayer in Unity and I've been stuck with an issue for a few weeks that I can't seem to fix. I have a game where you select a player and it instantiates a certain prefab determining on the player you selected and loads a new scene with the help of some tutorials I found on YouTube. The problem is with my photon view's and my photon transform view's I think or possibly my movement script. What happens is, I start the game and load in one player and everything works fine. Then when I open a second build, all of a sudden one build can control both characters, and the other build can't control anything. I have photon views and transform views on all of my prefabs and have been lost trying to fix this issue forever. Also none of the movement seem to be synchronized across the game as I might move the characters left on one build and they will not move on the second. I don't know if anyone has any clues on how to fix this but I would be more than happy to answer any questions if anyone knows a possible solution. Here is what I thought I was supposed to be doing for the movement code - private void FixedUpdate() { if(PV.IsMine) { ApplyMovement(); CheckSurrondings(); } }
Any help would be massively appreciated.
↧
Score problem
Hello, I am using the photon point system the problem is that when I add 1 point all the players of the game are added and I just want that if the player collects a point only the local player is added to it, I am new I'm waiting for your help thanks
↧
↧
Synchronize Player Hit with Mouse
Hey guys!
Im pretty new to Photon und im trying to make a topdown shooter (just for fun).
My problem now is, that i want to synchronize if the player clicked on an object (which has a rigidbody) so the shot will travel there.
The problem I am having is, that i dont want to use IPunObservable on the mouseposition of the player cause it sounds costly. (i have done a raycast through the mouseposition and checks if it hits something)
I dont know how I can send the Information of hitting the object to the other players.
(If the player hits a object, a raycast is sent from playerpos to objectpos)
Thanks a lot!
↧
How to add components and being registered for other players?
Hi,
First of all, sorry if this topic was already posted I couldn't manage to find it sorry.
I am making a RPG where I can apply status on enemies (like vulnerability bleed etc...) but all of those are components that I add on the GameObject of the enemy.
(for example I have a class bleed that I add on the GameObject of the player or the entity that is bleeding)
I am adding the created status to the list of the observed components but the only client that sees the photonview being actualize is the one that created the script.
Is there a way to bypass this? Am I doing something wrong?
↧
Troubles with instantiation and ownership
I'm experiencing some problems with instantiation and ownership in photon. I want to instantiate an object locally via rpc on everyone in the room and set ownership on that object in that rpc.
My code of spawner
public class PlayerSpawner : MonoBehaviourPunCallbacks {
[SerializeField]
RpcTarget rpcTarget = RpcTarget.AllBufferedViaServer;
void Awake() {
Vector3 position = Vector3.zero + Vector3.left * PhotonNetwork.LocalPlayer.ActorNumber;
Color color = Color.Lerp(Color.red, Color.green, (float) PhotonNetwork.CurrentRoom.PlayerCount / 10);
photonView.RPC(nameof(InitPlayerLocally), rpcTarget, PhotonNetwork.LocalPlayer, position, JsonUtility.ToJson(color));
Debug.LogError($"ID {PhotonNetwork.LocalPlayer.ActorNumber}");
if (PhotonNetwork.IsMasterClient)
Debug.LogError("Master");
}
[PunRPC]
void InitPlayerLocally(Player owner, Vector3 position, string color) {
Debug.LogError($"[RPC] from {owner.ActorNumber}");
var o = Instantiate(Resources.Load("Player"));
o.transform.position = position;
o.GetComponent().material.color = JsonUtility.FromJson(color);
// it doesn't make game object true networked
// if owner leaves - game object still exists in the scene. Why?
o.GetPhotonView().TransferOwnership(owner);
PhotonNetwork.AllocateViewID(o.GetPhotonView());
PhotonNetwork.RegisterPhotonView(o.GetPhotonView());
}
}
Player's photon view owner type is set to takeover
RPCs are buffered via server and I suppose they must be executed in the order they were sent and for players that come later, but it is not true.
Here is an example of 4 apps were run simultaneously: https://imgur.com/brfJBlD
Here is an example of 4 consecutive runs: https://imgur.com/CnaanLH
As I thought it should work this way:
1. Each player joining room creates an RPC with some initialization data
2. That player executes all RPC from the very old one up to the its own one
2. Each player in the room (Including RPC sender) execute the last sent RPCs
2.1. Each player instantiates a local object
2.2. After instantiation it transfers ownership of that object to the sender player
3. Newly created object is instantiated on each client and owner set to actual and the same player on each client
4. After player X leaves the room - each object, owned by X, get automatically destroyed on each other client, because they were already manually linked to that player
Summary:
1. Why buffered RPCs are not called on newly joined players?
2. Why owned object not destroyed after leaving the room?
Playable unity package of the scene: https://drive.google.com/open?id=1nLh8Tf1R9x3cunfFZrPzK-uq6xZW3lWF
↧
Don't destory GameObject on Player Disconnect
So I'm having a Scene in Unity where all players (6 players) spwan a Character with Photonnetwork.Instantiate(), and I want all the Characters to be in the Scene until the game ends (60 seconds) even if any player disconnects. So obviously as I checked if any player disconnects his Character gets destroyed in the Scenes of the other players.
Is there any option to keep them in the Scene with Photon code? Like DontDestroyOnDisconnect() or something?
↧
↧
How do I change material at runtime?
I am trying to change the material of my player at runtime in order to help distinguish players from eachother.
Currently, the changes go through, but they are applied to each player in the scene as opposed to the player that called the method.
public List RocketMaterials;
Renderer rocketRenderer;
private PhotonView _photonView;
private bool hasChangedMat=false;
void Start()
{
Debug.Log("Mat change start");
_photonView = GetComponent();
_photonView.RPC("ChangeRocketMaterial", RpcTarget.All);
}
[PunRPC]
public void ChangeRocketMaterial()
{
if (!hasChangedMat) {
Debug.Log("Change mat method;");
rocketRenderer = GetComponent();
rocketRenderer.enabled = true;
rocketRenderer.material = RocketColors[PhotonNetwork.PlayerList.Length];
hasChangedMat = true;
}
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting == true)
{
stream.SendNext(hasChangedMat);
}
else
{
hasChangedMat = (bool)stream.ReceiveNext();
}
}
I am fairly certain that the problem is that the code does not define which players material should be uppdated, but I have no real idea how to do that with Photon.
I also tried using photonView.IsMine as a requirement to make sure only the LocalPlayer runs it, which technically solved the problem, but as far as I am aware right now, not in a usable way
↧
Could use some help figuring out bouncy physics material in this PhotonEngine game
So I'm trying to prototype a primitive 1v1 fighting game where the goal is to push the opponent off of the platform rather than actually fight. This is working great in a local multiplayer setup using a physics material on the "belly" of the Rigidbody2d players (the circle collider gameobject nested inside of the square gameobject has the bouncy material).
But I'm toying with the idea of making it a network game and it seems the physics material doesn't get communicated too well over the Photon Realtime connections?
Here is a video showing how it seems like sometimes the position is updated but sometimes a player runs into another player and its like a brick wall:
https://imgur.com/QYWH178
Any ideas of what to try or if this is even possible?
A bit about how things are currently setup:
Each player object has the nested collider with a high bounciness material on it. Each player moves via the Rigidbody2D component via
.AddForce(direction * Speed);I have a `Photon View` component on the player prefab and a `Photon Rigibody 2D View` component that is checked to Synchronize Velocity and Angular Velocity, as well as a `Photon Transform View` component synchronizing Position. Both the transform view and Rigidbody2dView are Observed Components in the Photon View. I also found a script someone posted where they were manually sending the position/velocity data via `OnPhotonSerializeView()` I've tried adding that script and making that observable as well, but no luck, but it looks something like this:
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.IsWriting) { //We own this player: send the others our data stream.SendNext(transform.position); stream.SendNext(transform.rotation); stream.SendNext(r.velocity); stream.SendNext(r.angularVelocity); } else { //Network player, receive data latestPos = (Vector3)stream.ReceiveNext(); latestRot = (Quaternion)stream.ReceiveNext(); velocity = (Vector2)stream.ReceiveNext(); angularVelocity = (float)stream.ReceiveNext(); valuesReceived = true; } } // Update is called once per frame void Update() { if (!photonView.IsMine && valuesReceived) { //Update Object position and Rigidbody parameters transform.position = Vector3.Lerp(transform.position, latestPos, Time.deltaTime * 5); transform.rotation = Quaternion.Lerp(transform.rotation, latestRot, Time.deltaTime * 5); r.velocity = velocity; r.angularVelocity = angularVelocity; } }
↧
Photonview on child object of player with photonview
I have a player GameObject in my game with a photonview attached and it is observing the transform and the rigidbody.
A child object of the player GO has a particle emitter that can turn on and off. I would like to synchronize the particle emitter's state.
How do I best accomplish this?
Thank you.
↧
How to get the transform (position) of a photon instantiated object instantiated by another client??
Hi, I've just started transforming my game into a multiplayer game. In my game there is a flag that people can carry around, lose, respawn, float up and down... Summing up, it moves a lot.
Right now, the flag is spawned by the first player that enters the room. All the players have a HUD that contains an arrow that points to the flag always. To do this, I always follow the transform.Position of the flag gameObject. When I'm the first player, it is easy to get the transform when I'm instantiating it. However, I do not know how to get this information as the next players joining the room.
Any help or link to a guide would be appreciated, as I cannot find any clue of how to do this in the documentation.
↧
↧
PhotonView with ID 1001 has 2 methods "ReducePlayerHealth"
PhotonView with ID 1001 has 2 methods "ReducePlayerHealth" that takes 1 argument(s): Int32. Should be just one?
UnityEngine.Debug:LogError(Object)
Photon.Pun.PhotonNetwork:ExecuteRpc(Hashtable, Player) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:537)
Photon.Pun.PhotonNetwork:RPC(PhotonView, String, RpcTarget, Player, Boolean, Object[]) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:1078)
Photon.Pun.PhotonNetwork:RPC(PhotonView, String, RpcTarget, Boolean, Object[]) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetwork.cs:2737)
Photon.Pun.PhotonView:RPC(String, RpcTarget, Object[]) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonView.cs:410)
Dmg_Destroy:Damage(PhotonView) (at Assets/Scripts/Spells/Dmg_Destroy.cs:64)
Dmg_Destroy:OnTriggerEnter2D(Collider2D) (at Assets/Scripts/Spells/Dmg_Destroy.cs:119)
I know for a fact there is only one method called "ReducePlayerHealth".
What is going on with this?
↧
Inverse Kinetics Is Not Working
I'm developing a multiplayer app for both the Oculus Rift and Quest using Unity, PUN 2 (Photon View, Photon Animator View, etc.), and the VRIK feature of Final IK (from the Unity Asset Store). In terms of humanoid model avatar motions following the player's hand and head motions, for the Rift everything works fine except that the other player's avatar is in its default state (in my case with the arms elevated and extended away from the body) and completely motionless.
For the Quest everything's fine for the first player until the second player enters the room, at which point the hands of both players' avatars lock up and can't be moved.
Any insight as to how to resolve these issues will be greatly appreciated.
↧
Is the 3gb of traffic on the one time 100 CCU for each month or all 60 months?
I am looking into the 100 CCU plan for Photon PUN. It says that it "Includes 300 GB Traffic", and I was wondering, is this per each month, or is this the amount of traffic for the entire 5 years?
↧