Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Snap To Grid On Client (No Interpolation)?

Discussion in 'Netcode for GameObjects' started by gamecreatorc1, Feb 26, 2023.

  1. gamecreatorc1

    gamecreatorc1

    Joined:
    Dec 12, 2019
    Posts:
    59
    I was making a snake game for fun and practice but ran into an issue. The snake and its segments are snapped to grid (represented as integers). On the host this works perfectly, as you'd expect. But on the client, the snake doesn't snap but instead drifts over the lines. I understand this this is likely due to interpolation or prediction or whatever Unity does but I specifically don't want this effect. I would like the head and segments to always snap as integers. What's the best way to do this?

    I tried unticking the interpolate option in the prefab and messing with the position threshold but nothing seemed to have the effect I wanted.

    I thought of at least one workaround where I send the positions of each piece instead and interpret where the piece should be myself. For example, if the piece was going right and its x position is 1.4, it should be at 2. But there are probably smarter ways to do this.
     
  2. lavagoatGG

    lavagoatGG

    Joined:
    Apr 16, 2022
    Posts:
    229
    Maybe you can send the position of the head from the server via ServerRPC and update the snake on client because you have the current body.
     
  3. gamecreatorc1

    gamecreatorc1

    Joined:
    Dec 12, 2019
    Posts:
    59
    Thanks. That may be a smarter way to go about it since I don't have to worry about drop-in connections.