jalmasi / vrspace

VRSpace: Multiuser Virtual Reality Engine
Apache License 2.0
173 stars 79 forks source link

in VR, avatar vertical position, height and arm movement messed up #20

Closed jalmasi closed 1 year ago

jalmasi commented 2 years ago

By default, we send up to 5 events per second, and create animations to interpolate in between. This is controlled by fps and createAnimations, so if you want to see your arm movements as they are, set fps=25 and createAnimations=false. I don't think these have anything to do with the bug though.

Sending side is trackChanges(), specifically

      // track camera movements
      if ( this.camera.ellipsoid ) {
        var height = this.camera.globalPosition.y - this.camera.ellipsoid.y*2;
        if ( this.camera.ellipsoidOffset ) {
          height += this.camera.ellipsoidOffset.y;
        }
        this.checkChange("position", this.pos, new BABYLON.Vector3(this.camera.globalPosition.x, height, this.camera.globalPosition.z), changes);
      } else {
        this.checkChange("position", this.pos, this.camera.globalPosition, changes);
      }
...
        // track and transmit userHeight in VR
        if ( this.isChanged( this.userHeight, vrHelper.realWorldHeight(), this.resolution)) {
          this.userHeight = vrHelper.realWorldHeight();
          changes.push({field: 'userHeight', value: this.userHeight});
        }

The method later sends all changes in one packet, like VRSPACE.sendMyChanges(changes). The purpose here is to calculate where your feet are. Then on receiving side, when we load the avatar (loadAvatar method), we add a parent mesh, and use it to move the avatar around (changeAvatar method) like

      if ( 'position' === field ) {
        if ( ! obj.translate ) {
          obj.translate = VRSPACEUI.createAnimation(node, "position", this.fps);
        }
        VRSPACEUI.updateAnimation(obj.translate, node.position, obj.position);
...
      } else if ( 'userHeight' === field ) {
        avatar.trackHeight(obj.userHeight);

If we're lucky, this is simply feet position being miscalculated on sending side. But I don't see anything obviously wrong with it. More likely, it's mess with avatar positioning. Note that network events get routed to the same trackHeight() method that is a hack with hardcoded numeric values. So what I'd do here is, comment out calls to trackHeight() and see what happens.

There's a chance we need to call Avatar.recompute() at some point. I hope not, as it may be computationally heavy. I'm not clear when it has to be called.

jalmasi commented 1 year ago

Babylon.js 5 introduced breaking changes with GLTF characters. Reverted to babylon 4 until it stabilizes.