Forum Discussion

rico.stenson's avatar
2 months ago
Solved

Laggy inputs in Horizon Worlds

I am trying to get lag free input for my game for Horizion Worlds.  

In type script I am trying to get ray cast input taps and then move an object to that position or drag it where the cursor moves.  However, there appears to be about 1/4th of a second lag no matter what I do.  I have the script marked as local as suggested in the documentation but still there is a lag from the click on screen in Focus mode and when my actual object moves.  

Does anyone know what I'm missing here?  The automatic cursor that is drawn is lag free, but the object that I trying to move with click lags behind.

Here is the code using the sysEvents from one of the samples.  Supposedly this should be running fully locally and therefore lag free, but it isn't. 

 // Tracking Focused Interaction inputs 

    this.connectLocalBroadcastEvent(hz.PlayerControls.onFocusedInteractionInputStarted, (data) => {

      const firstInteraction = data.interactionInfo[0];

      if (firstInteraction.interactionIndex !== 0) return;

      this.MoveObjectToTouchPos(data.interactionInfo[0]);

      }

    });

Thoughts? 

  • Hey!  That was it!  Thanks jackmw94​ 

    I just needed to set the objectToMove.owner to be the owningPlayer of the entity.  Wow... That was not obvious lol!  Thanks so much! 

    Here is the code for anyone dealing with this same issue.  This is a modification of the sysFocusedInteractionManagerLocal.ts 

     this.owningPlayer = this.entity.owner.get();

        if (this.props.objectToMove) {

          this.props.objectToMove.owner.set(this.owningPlayer);

        }

    For lag free input you must use the connectLocalBroadcastEvent, not the network version.  

3 Replies

  • Although the script is marked as local, is the entity on which it's attached also owned by the player? I assume yes since we're using PlayerControls and I think that only works locally but worth the question to sanity check!

    Other question is could the object you're moving be transferred to the player when you're moving it? I think that would give the local player authority over it's position and therefore reduce the server request-to-move delay?

    • rico.stenson's avatar
      rico.stenson
      Member

      Hey!  That was it!  Thanks jackmw94​ 

      I just needed to set the objectToMove.owner to be the owningPlayer of the entity.  Wow... That was not obvious lol!  Thanks so much! 

      Here is the code for anyone dealing with this same issue.  This is a modification of the sysFocusedInteractionManagerLocal.ts 

       this.owningPlayer = this.entity.owner.get();

          if (this.props.objectToMove) {

            this.props.objectToMove.owner.set(this.owningPlayer);

          }

      For lag free input you must use the connectLocalBroadcastEvent, not the network version.