In a multiplayer game I’m buildling, I’m importing an elevator glb model which animates moving up and down, using AnimationMixer and clipAction.
I want the position of the elevator to be synchronized across multiple sessions that are in the same room; sessions communicate their positions and other things to one another over websocket.
I’ve attempted to write code like this:
let animationMixer: AnimationMixer;
function animateModel(model: Group, animations: AnimationClip[]) {
animationMixer = new AnimationMixer(model);
const clipActions = animations.map((clip) => animationMixer.clipAction(clip));
clipActions.forEach((action) => action.play());
const currentTime = (new Date().getTime()) / 1000;
animationMixer.setTime(currentTime);
}
// r3f function:
useFrame((_, delta) => {
animationMixer?.update(delta);
})
However, this doesnt seem to always work, especially if there are many elements in the scene, the elevator position gets out of sync.
Anyone have any strategies or suggestions for doing this?