Page 1 of 1
Smoothing Out Multiplayer Movement
Posted: Tue Aug 08, 2023 10:21 pm
by Sammm
Hello! I've created some basic multiplayer movement code, but right now everything looks super jittery. My code to draw clients is basically just:
Code: Select all
for k, v in pairs(server.playerData) do
love.graphics.circle("fill", v.x, v.y, 50) -- Draw player graphic exactly at position
end
I'm using a physics engine so I can't simulate the client in real time, since everything that moves is variable. I just need to figure out how to add some basic interpolation or something so that the movement of other clients and entities can be smoothed out. I've looked for a ton of sources already but everything I saw uses Unity or has some long winded approach that I believe is overkill for such a simple game I'm creating (a 2D platformer dodge game). If someone could perhaps demonstrate some simple pseudo code or at least point me in a reasonable direction to go forward with implementing this, I would greatly appreciate it!
Re: Smoothing Out Multiplayer Movement
Posted: Wed Aug 09, 2023 7:14 am
by Bobble68
I will admit I haven't messed around with multiplayer much, but I could give some suggestions. My first instinct is to record its last known position and speed, and just use that to guess its next positions linearly until you get the next position to correct it. I think that should make it less jittery, though in some circumstances it might look odd.
Re: Smoothing Out Multiplayer Movement
Posted: Wed Aug 09, 2023 7:56 am
by dusoft
Sammm wrote: ↑Tue Aug 08, 2023 10:21 pm
Hello! I've created some basic multiplayer movement code, but right now everything looks super jittery. My code to draw clients is basically just:
Code: Select all
for k, v in pairs(server.playerData) do
love.graphics.circle("fill", v.x, v.y, 50) -- Draw player graphic exactly at position
end
I'm using a physics engine so I can't simulate the client in real time, since everything that moves is variable. I just need to figure out how to add some basic interpolation or something so that the movement of other clients and entities can be smoothed out. I've looked for a ton of sources already but everything I saw uses Unity or has some long winded approach that I believe is overkill for such a simple game I'm creating (a 2D platformer dodge game). If someone could perhaps demonstrate some simple pseudo code or at least point me in a reasonable direction to go forward with implementing this, I would greatly appreciate it!
Maybe tweening between position A and position B? This could also look weird. But if you allow movement only in certain directions, then also approach suggested above, taking direction and speed in account, could work.