Forum Discussion

gytaco's avatar
gytaco
MHCP Member
11 months ago
Solved

Disable/Override VR/Mobile Joystick

I am learning the desktop editor.

I am trying to make some more intuitive driving/flying controls then is currently being shown in "Driving Simulator", and trying to see if there is better support with the Desktop Editor. I have added a Seat AvatarPose to get the character to sit, however any inputs from the left axis control moves the player out of that pose. Is it possible to disable or better yet reassign the controls to move the asset while the character is sitting?

Without having to grab an item or override?

I am using a trigger gizmo at the moment on the AvatarPose. The only hints online show that I have to grab an item to override buttons, but that doesnt override the Left Axis and also grabbing something to control it is very unintuitive for the user as evidenced by interacting with a number of Worlds.


4 Replies

  • For VR and Desktop users, it is possible to intercept the movement axis without the player holding an item. This is possible thanks to the PlayerControls API. The reference documentation can be found here:

    https://developers.meta.com/horizon-worlds/learn/documentation/create-for-web-and-mobile/typescript-apis-for-mobile/custom-input-api

    For mobile, there isn't an equivalent API. There is however a focused interaction mode that allows you to detect when the player touches the screen, when the touch location moves, and when it ends. Here's the documentation:
    https://developers.meta.com/horizon-worlds/learn/documentation/create-for-web-and-mobile/typescript-apis-for-mobile/focused-interaction

    One approach could be setting the player locomotion to 0, and using a combination of the above techniques to maneuver the vehicle. Note that with focused interaction the locomotion and jump speed is already set to 0, until the player presses E.

    All these controls interactions require local scripting.

    • gytaco's avatar
      gytaco
      MHCP Member

      Sorry for the delay.

      I can confirm that none of those options work at all. It appears these behaviours cannot be overridden or interrupted

      .

      I'd love any other options or input in overriding default behaviors.

       

      Here is the code you can run yourself.

      import * as hz from 'horizon/core';

      class controlsTest extends hz.Component<typeof controlsTest> {
        static propsDefinition = {};

        input?: hz.PlayerInput;
        player!: hz.Player;

        start() {
          console.log('Registering the player entering the world.');
         
          // Register to receive the OnPlayerEnterWorld event.
          this.connectCodeBlockEvent(
            this.entity,
            hz.CodeBlockEvents.OnPlayerEnterWorld,
            player => {
              console.log('Setting entity Owner ' + player.id);
              this.entity.owner.set(player);
             
              hz.PlayerControls.disableSystemControls();
            },
          );

          //hz.PlayerControls.disableSystemControls();
         
          // This script must run on the client.
          if (this.entity.owner.get().id != this.world.getServerPlayer().id) {
            const options = {preferredButtonPlacement: hz.ButtonPlacement.Center};

            // Test that the jump action is supported.
            if (hz.PlayerControls.isInputActionSupported(hz.PlayerInputAction.Jump)) {
              // Set player input to the jump action, set the on-screen button
              // icon to the jump icon, and set the button placement to center.
              // third parameter is the disposableObject, which is set to "this".
              this.input = hz.PlayerControls.connectLocalInput(
                hz.PlayerInputAction.Jump,
                hz.ButtonIcon.Jump,
                this,
                options,
              );

              //diable the jump action
              //this.input.disconnect();
                           
              // Register to receive the jump action when the player presses the spacebar.
              this.input.registerCallback((action, pressed) => {
                // Set spacebar to the jump action.
               
                const keyName = hz.PlayerControls.getPlatformKeyNames(action)[0];
                console.log('Action pressed callback', action, keyName, pressed);
                return false;
              });
            }
          }
        }
      }
      hz.Component.register(controlsTest);
  • Hi gytaco!

    With the release of  v214 (release notes here), there is a new Avatar Pose Gizmo API that allows you to

    • Specify which players can use an avatar pose gizmo.
    • Place a player in an avatar pose gizmo.
    • Specify if the player is allowed to exit the gizmo.

    Using these new features to disable players exiting the gizmo, and dynamically removing them when needed should resolve the issue you've described.

    Happy creating!

    Pose Gizmo Documentation: https://developers.meta.com/horizon-worlds/learn/documentation/code-blocks-and-gizmos/avatar-pose-gizmo

     

    • gytaco's avatar
      gytaco
      MHCP Member

      Perfect! Yes the new disallow player to exit the Gizmo allows me to access controller functionality to control other behaviors.