Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to sync server and client models using TranslateBy in render step and heartbeat?

Asked by 5 years ago
Edited 5 years ago

I have a ship that can be piloted by a player.

  1. The ship has a speed value that determines how fast to move it.
  2. The client uses remote functions to set the speed of the ship.
  3. Each client translates the model in render step, and the server translates in heartbeat.

However I have a very strange problem, the server is completely smooth but the client has some parts that are left behind, it almost seems like the network is syncing before TranslateBy is done moving all the parts.

Example

Server(Smooth) ! Gif

Client(Some parts of the model are left behind until the next sync) ! Gif

Note when I play the game in the studio(Play not Test) the client is very smooth.

Code

Client

RunService:BindToRenderStep("move", Enum.RenderPriority.First.Value, function (delta)
    for i, ship in ipairs(localShips) do -- localShips contain the models
        local dt = (delta * 1000) / 16
        local tSpeed = ship.speed.Value / 60

        ship:TranslateBy(ship.PrimaryPart.CFrame.lookVector * (tSpeed * dt))
    end
end)

Server

RunService.Heartbeat:Connect(function (delta)
    local dt = (delta * 1000) / 16
    local tSpeed = ship.speed.Value / 60
    ship:TranslateBy(ship.PrimaryPart.CFrame.lookVector * (tSpeed * dt))
end)

Note

  1. The parts are anchored.
  2. I can't use any physics(body movers, motor6d).
  3. I have tried to stick the loops into their own coroutines and calculate my own delta.
  4. All parts have the same parent(should not matter).

Question

Any idea on why this is happening?

Is there a better way to do this?

0
Why are you moving the ship in both the client and server? Any changes made to the server will replicate to the client, so translating the ship in the server will also move it in all clients. chomboghai 2044 — 5y
0
Because movement is choppy if I rely solely on the server (Server updates at 20Hz) jermy1145 0 — 5y
0
Give network ownership to the player piloting the ship chomboghai 2044 — 5y
0
I can't, the model is anchored. jermy1145 0 — 5y

Answer this question