Search Unity

Handling movement, how often to save player positions

Discussion in 'Multiplayer' started by Thimble2600, May 27, 2019.

  1. Thimble2600

    Thimble2600

    Joined:
    Nov 27, 2015
    Posts:
    165
    I've recently gotten rid of my 2D tile-based path finding system.

    Before I would save player positions every time they reached a new tile, but since I'm not using tile-based path finding any more I'm wondering how often or during what event I should update their positions.

    I could update it when they change tile, but if I'm saving their position as a floating-point it doesn't seem right that I repeatedly convert their world position to tile position to check whether they've changed tiles or not.

    Should I update their positions when they click to move and the point they're moving to? This would mean that anyone who encounters them would see that they're moving.
    gif of players moving https://imgur.com/yIVg0z7

    Thought I'd ask, what's the smart thing to do here?

    I've not added any collision since removing the tile-based path finding. Player movement is very basic at the moment.

    Code (CSharp):
    1.  
    2.         private void FixedUpdate()
    3.         {
    4.             transform.position = Vector3.MoveTowards ( transform.position , movingTo , movementSpeed );
    5.         }
     
    Last edited: May 27, 2019
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    It really depends what you need for.
    If is enough for saving every tile reach, that is fair enough.

    Question, what you mean by saving?
     
  3. Thimble2600

    Thimble2600

    Joined:
    Nov 27, 2015
    Posts:
    165
    Writing the position to a database.
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    You don't want write stuff to DB too often. Surely not every 0.2, or 0.02 seconds. If anything, you want keep data in server memory, to distribute between players, if that what you need.

    I suggest, you get read upon, how FPS games does store and save positions, or even RTS games.