Hi everyone,
I’m working on a multiplayer game with Havok physics and Socket.IO.
The forces are exchanged between players through sockets, and the players are synced correctly.
But sometimes, the ball doesn’t behave the same on both clients (it desyncs).
Has anyone faced this issue before? What’s the best way to keep physics objects like a ball perfectly synced across clients?
//client
//onDragEnd
socket.emit('applyForce', { meshId: pickedMesh.id, force: force, position:meshPos, room: roomRef.current })
pickedMesh.physicsBody.applyImpulse(force, meshPos);
//on applyForce event
function onApplyForce(data: { meshId: string, force: Vector3, position: Vector3}{
const { meshId, force, position } = data
const mesh = currentSceneRef.current?.meshes.find(mesh => mesh.id === meshId)
if (mesh && mesh.physicsBody)
mesh.physicsBody.applyImpulse(force, position);
}
socket.on('applyForce', onApplyForce)
}
//server
socket.on("applyForce", (data) => {
const { meshId, force, position, room }=data
socket.to(room).emit("applyForce", { meshId, force, position });
});