Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Tile based Game networking issue

Discussion in 'Editor & General Support' started by countlesschain, Jun 2, 2018.

  1. countlesschain

    countlesschain

    Joined:
    Jun 2, 2018
    Posts:
    6
    Hello, i am currently experimenting with making a 3d tile based game.

    So far in my game a map is generated and the character is spawned on the first tile the character clicks.
    I also built a path finding system so that the character moves to a target tile (that is clicked).

    The problem i have run into is that while moving from tile to tile based on the path calculated by the pathfinder, the two players move at different speeds. From multiple tests, i figured out that it does not matter which is host and which is client. Instead, the game being run from the unity editor moves the character significantly slower than the game run from a built verson.

    Here is the code for movement. The two parameters are: t = target tile, p = current tile. It happens on client side and networktransform transmits the position updates.

    Code (CSharp):
    1.     private IEnumerator Move(Transform t, Transform p)
    2.     {
    3.         moving = true;
    4.         for (int z = 0; z < 30; z++)
    5.         {
    6.             yield return new WaitForSeconds(Time.deltaTime);
    7.             model.position = Vector3.MoveTowards(p.position + new Vector3(0, 1f, 0), t.position + new Vector3(0, 1f, 0), 2f*z*Time.deltaTime);
    8.         }  
    9.         Debug.Log("check");
    10.         CmdTile(t.gameObject, model.gameObject);
    11.         yield return new WaitUntil(() => model.GetComponent<CharClass>().pos == t.gameObject);
    12.         currentpath.RemoveAt(currentpath.Count - 1);
    13.         moving = false;
    14.     }
    The character model has a sync var with the value of the tile the character is currently standing on. This value is changed with the CmdTile() command used above and the code is just:

    Code (CSharp):
    1.     [Command]
    2.     void CmdTile(GameObject tile, GameObject obj)
    3.     {
    4.         obj.GetComponent<CharClass>().SetPos(tile);
    5.     }
    How can i modify my game so that the speed the characters move at from tile to tile is the same?
    If the speed is only slower when being run from the editor, does that mean that if i have two built version of the game they will move the same speed?

    Screenshot for visual reference:
     

    Attached Files:

  2. countlesschain

    countlesschain

    Joined:
    Jun 2, 2018
    Posts:
    6
    Solved, all is well.