- Home /
[UNET] Objects other than the local player's have a small jitter when moving.
I'm trying to create something that when a player stands on it, they will move with it for a 2d top down game (think like a moving platform). I've gotten that logic to work as it's fairly simple, but what I am having issues with is properly communicating that with the other clients.
Whenever say 2 players get on the moving object they will move with it as expected, but any other player will jitter in the direction that the object is moving. To make things worse (since this object in the end is supposed to be a ship that one of the players can fly) the intensity of the jitter increases with speed. I assume the issue comes from how I'm syncing the movement across the server.
Here is a GIF of the issue -> https://gyazo.com/7767531ab77817c0622197c9db8aa343
In the GIF I have the "ship" moving up at a velocity of 1 by using rigidbody2d.velocity. Below is my code on the player objects.
if (!hasAuthority)
{
//This is not the player object so we need to update stuff to match the server
transform.position = Vector3.SmoothDamp(transform.position, serverPosition, ref serverPositionSmoothVelocity, 0.25f);
}
And here is how I move the player and then sync up with the server.
private void AuthorityMovement()
{
//Any logic for moving should go here.
//We should make sure if we're on a ship then we should be moving with the ship
if (Ship != null)
{
transform.position += Ship.transform.position - shipOldTransform;
shipOldTransform = Ship.transform.position;
}
//Get the movement input from the player.
float horizontalMove = Mathf.Lerp(0, Input.GetAxis("Horizontal") * MoveSpeed, 0.8f);
float verticalMove = Mathf.Lerp(0, Input.GetAxis("Vertical") * MoveSpeed, 0.8f);
//Go through the various possibilities for what the player is trying to do.
if (PlayerPosition == Position.Empty)
{
PlayerRb.velocity = new Vector2(horizontalMove, verticalMove);
}
//Sync our movement up with the server
CmdUpdatePosition(transform.position);
}
[Command]
void CmdUpdatePosition(Vector3 newPosition)
{
serverPosition = newPosition;
}
I'm fairly new to UNET, but I've been giving it my best and this has been stumping me for a weekend or more, and any help or suggestions are welcome.
Answer by ADustyOldMuffin · Oct 24, 2018 at 12:55 AM
So I've made some progress on the problem, and I after some debugging and frustration I have found that it is actually only the sprite that is jittery. If anyone has any tips on what this could be or how to fix it I would love any suggestions.
Things I have tried: Lerping the movement before it is saved, Lerping the movement when it applies, Changing the channel of the syncvars on the PlayerObject
No such luck, I assume the problem comes from the camera of the client not being snapped on the pixels, and that would explain why the client is always perfect in focus. I'll keep digging.
And even better than this, it happens in 3D also.
Your answer
![](https://koobas.hobune.stream/wayback/20220612180726im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Teleport Not Working in Unity 2D 1 Answer
Move a whole enemy object to a new point 1 Answer
Question on Sprite and Movement 0 Answers