- Home /
 
MLAPI Help Pushing the local player to the forefront only on local perspective
Hello, I have started using MLAPI this week and have gained quite a bit of progress on my 2D game. Most of the functions that I want to be specific to the local player can be fixed with the IsLocalPlayer boolean. However I have reached a problem that has stumped me. The goal is to have a platformer similar to Maplestory and hence players do not collide with one another and can overlap each other on the x and y plane. I would like to make the local player at the forefront perspective so naturally I coded it to push the player into the forefront by changing the z
 void Awake()
     {
         z = this.gameObject.transform.position.z;
         z -= 1f;
      }
 
 void Update()
     {
         if (!local) local = IsLocalPlayer;
         else
         {
             this.transform.position = new Vector3(this.transform.position.x, this.transform.position.y, z); //this line makes sure the local player is always at the forefront relative to other players
             Move(); // script to move my player
             Track(); // script to move the camera 
         }
     }
 
 
               However I have a network transform component attached to the player which handles the x and y positions. I hence realize that no matter what Z I set, it will be sent across the server and eventually all players will have the same Z resulting in the engine not sure which player to place at the forefront resulting in a blend of alternating players at the forefront.
Anyone got any ideas to force the player to always be at the forefront relative to others? ( I could edit the NetworkTransform script but I would very much like to leave that intact and it is a final resort.)
Answer by GetLitGames · Jun 13, 2021 at 01:47 PM
I recommend Photon Bolt, but if you want to continue to use MLAPI (which I STRONGLY recommend against) then this confusing line gives you the local player in some way: if (NetworkManager.Singleton.ConnectedClients.TryGetValue(NetworkManager.Singleton.LocalClientId, out var networkedClient))
I got that from: https://docs-multiplayer.unity3d.com/docs/tutorials/helloworldtwo
Yes you are right, that line does allow you to retrieve the local client however it does not solve the issue of the synchronized z axis coordinates.
Your answer
 
             Follow this Question
Related Questions
Top Down 2D Network Transform 0 Answers
Simpler way to do 2D multiplayer? 2 Answers
Detecting when the other player presses a button 1 Answer
Syncing SpriteRenderer Between Clients 0 Answers