Why player is lagging (local multiplayer) - unity3d

Why my player lagging? I mean he is moving with 2 fps for enemy. Example: Player1 moves, in his screen all is ok. But player2 see player1 with 2 fps. And the same with player1.
Here is my prefab, and yes, I can't use RigidBody Transform

I think you could find the answer with very little research. The answer is quite simple though.
The reason why it's working perfectly on the client which owns the networking transform is because his input is directly reported to the game. On the other hand, the 2nd player has to send the information about his position to the host or simply the other players. The information is only sent a couple times per seconds.
You could increase the message sending rate of the networking but that's not really a good option. The best option would be to smooth the player's movement by assuming where he is going to be or move the player after it has moved already.
Here is a link about it : https://www.youtube.com/watch?v=Glm0nJ4sO5E

Related

Why does using PhotonRigidbody2DView give 'elastic' movement?

I'm currently using photon pun 2 to learn simple 2d multiplayer.
Using PhotonRigidbody2DView is giving an 'elastic' movement to the player. The player goes forward a bit and then returns to the original position.
Here's the video:
https://youtu.be/HgFVsofVZcQ
Why does this happen and how do I solve this?
I tried using PhotonTransformView and PhotonTransformViewClassic but it is giving weird results. The players go inside each other and when one player collides the other, the other player starts jittering.
So I decided to use PhotonRigidbody2DView instead. Now the players don't go inside each other and the jittering is also not happening but the 'elastic' movement problem is happening.
This happens because the remote client uses the velocity of the rigidbody to reproduce the movement of the character is does not control. This makes it a bit independent from the lag but for arcade style movement (where direction changes are immediate), this doesn't work all that well.
Solutions to this depend on what you actually need. Networked objects combined with physics can be tricky to get right. For PUN 2, we didn't implement a solution to this case and assumed you'd tweak the PhotonRigidbody2DView as needed.
The Smooth Sync package in the Asset Store seems to do well and is a plugin to PUN 2.
Alternatively, the newer Photon SDK "Fusion" should do better and is state of the art as networking solution.

How to prevent jitter with Network Transforms in Netcode?

We currently are working on a multiplayer game with Unity Netcode. The game is a racing game with relatively high speed. The player objects get synchronized with the Network Transform component.
We have the problem that the player is lagging a little bit (or junpig some steps forward instead of moving smooth).
The interpolate setting on the Network Transform makes it a little bit better but not completely.
Something we could observe is that when the own camera isn't moving, the other player isn't lagging at all, but since we have a racer game the camera moves all the time.
We could finally fix the problem. More information: https://forum.unity.com/threads/how-to-prevent-jitter-with-network-transforms-in-netcode.1387044/#post-8733624

My Netcode sample has frame skip problem even in a simple local network

I am using Netcode for a simple 1 vs. 1 football game.
Players and the ball have frame skip problem even in a simple local network.
I added the "ClientNetworkTransform" component to sync the positions of the players and the ball and even wrote a simple position sync component by myself, but both have the same frame skip problem.
by the way, I don't want to use interpolation because players and the ball slide while they move.
Here is the recorded video:
This is a Host-Client method. It also has this problem when I use the Server-Client method.
https://www.youtube.com/watch?v=HDWkdlzdNeQ
What is your suggestion?

Who should call RPC function while hit by a bullet

My question is simple.
Im creating top down 2D shooter game via PUN2 Free in Unity.
I want to synchronize collisions through network, to avoid lags inaccuracy.
A player is firing a bullet and it hits enemy. I want players to know about all bullets hits(to reduce health, get kill, etc.).
Should I call RPC_Hit() from shooter to other players to inform about actual hit or it would be more wise to call RPC_Hit() from hurt player to other players in game.
Im asking in terms of better synchronization, I guess lags will happen, so in my oppinion it would be better to call RPC function from player which got hit, but then if I would need to send callback only to shooter(for example, to let him now how many dmg he did) it would be hard, cause I can only send RPC to "MasterClient,All,Others".
This bothers me.
I can not find any informations about this.
In same moment the Player1 and Player2 view differs cause of Lag

unity3d player gameobject "hear" sounds

I have a question that is a little... complex
basically I want a gameObject (an enemy) "listen" to the sound of the player (footsteps, door opening, gunfire etc)
I could do this just fine by using:
>Collider[] hitColliders;
>hitColliders = Physics.OverlapSphere(transform.position, 10f,enemyLayer);
>
>for(int i=0;i<hitcolliders.Length;i++){}// Call Enemy Hear Player Function
However, the problem starts here:
I want the "sound" to be blocked by walls. At first, I thought I could use Physics.Linecast to do this. However, this means the sound could be blocked by a mere piece of pole, because Physics.Linecast only shoots a single, straight line.
What I want is player C could not hear anyone at all, but player A and B could still hear each other.
I hope you guys understand my question.
You could place the objects you want to block the soundwave on a specific layer. And just make the raycast ignore all other layers.
Leave all this Physic and other graphical stuff behind.
Create a separate logic for this behavior.
Create a big chess board (where x,y will be x,y position in you game) and add only sound-generators, sound-listeners and sound-obstacles.
Update this chess board each frame and create sounds, fly sounds, block sounds and listen to sounds and act appropriate as the real life actors.
This way you can add parameters to each obstacle, sound-generator and sound-listener so that all be configurable.