Godot XR Tools

repository·master·Indexed 20 days ago

https://github.com/godotvr/godot-xr-tools

A collection of support files and scenes for AR and VR interfaces in the Godot game engine. It provides ready-to-use XR functionality including locomotion (direct movement, teleportation, climbing, gliding, sprinting), interaction systems (pickable objects, snap-zones, poke interaction, hand-pose detection), and specialized interactable nodes like joysticks, sliders, and buttons. Includes a predefined physics layer system for managing interactions between players and the environment.

Tokens
2.3K
Snippets
2
Records
15
Agent score
72%

What's inside Godot XR Tools

  1. Explore Teleport and Turning via the Teleport Demo scene

    master

    The teleport_demo scene is a reference implementation used to verify and demonstrate teleportation motion and turning mechanics. It includes various test objects scattered throughout the environment to allow players to test teleportation accuracy and movement.

    This demo specifically showcases:

    • Teleport: Moving the player to a new location via a teleportation mechanism.
    • Turning: Rotating the player's orientation.

    You can use this scene to ensure your XR setup and the godot-xr-tools teleportation components are configured correctly before implementing them in your own project.

  2. Implement sprinting movement with XRToolsMovementSprint

    master
    To implement sprinting in your XR project, use the XRToolsMovementSprint provider. In a standard configuration, sprinting is enabled by holding down the left joystick button. This provider is designed to work within the existing XR Tools movement system to augment standard locomotion with a sprint capability.
  3. Use snap-zones with snap_tray.tscn

    master

    To create a container or surface that holds specific objects in fixed positions, inherit from Object_pickable.tscn and implement snap-zones.

    In the snap_tray.tscn example:

    • The tray itself is a pickable object that can be moved.
    • It contains multiple snap-zones (areas where objects can be automatically aligned and snapped).
    • These zones can be used to snap various test objects (e.g., red or yellow objects) to specific locations on the tray.
  4. Use XRToolsPoke for UI and object interaction

    master

    The XRToolsPoke node allows users to interact with user interfaces and objects by simulating touch/poke interactions. In a typical setup, XRToolsPoke nodes are attached to the index finger tips of both hands using BoneAttachment nodes.

    When interacting with UI elements, the XRToolsPoke node triggers standard Godot UI events:

    • pointer_pressed
    • pointer_moved
    • pointer_released
    // Note: This is a conceptual representation of the node's behavior in a scene tree
    // XRToolsPoke nodes are typically children of BoneAttachment nodes on the hand skeleton
    // to track the index finger tip.
  5. Prevent shader compilation hiccups in XR

    master

    Because many functions in this module hide and show objects, users may experience performance hiccups when Godot compiles shaders on-the-fly during gameplay.

    To prevent this, you can pre-compile the required shaders by adding the provided shader cache scene to your camera hierarchy.

    Steps:

    1. Locate the scene misc/VR_Common_Shader_Cache.tscn within the module.
    2. Add this scene as a child node to your XRCamera3D.

    This ensures the shaders are compiled when your main scene first loads, rather than when an object is first shown to the user.

    Scene Tree Structure:
    XRCamera3D
    └── VR_Common_Shader_Cache (tscn)
  6. Implement hand-pose detection

    master

    To detect specific hand poses in your XR scene, follow this setup pattern:

    1. Detect Poses: Add XRToolsFunctionPoseDetector instances as siblings to both hands.
    2. Define Areas: Add XRToolsHandPoseArea nodes to the specific areas where poses should be detected.
    3. Configure Settings: Assign XRToolsHandPoseSettings resources to the XRToolsHandPoseArea nodes to define the pose requirements.
  7. Install Godot XR Tools library

    master

    You can obtain the XR Tools library for your project in two ways:

    1. Releases: Download the official release from the GitHub releases page.
    2. Godot Asset Library: Search for and download it directly within the Godot editor's Asset Library.

    Note: If you are using the full demo included in this repository, you must also install the OpenXR plugin separately (available via the Godot Asset Library or OpenXR releases) for the demo to function.

  8. Explore basic movement providers in the Basic Movement Demo

    master

    The basic_movement_demo scene serves as a reference implementation for common XR locomotion and movement mechanics. You can use this scene to verify the configuration and behavior of the following movement providers:

    • Direct Movement: Locomotion where the player moves through space via controller input.
    • Turning: Mechanics for rotating the player's orientation.
    • Jumping: Vertical movement capabilities.
    • Crouching: Height adjustment mechanics.

    The demo includes various test objects (platforms/obstacles) designed to be walked onto or jumped upon to validate that these movement systems are functioning correctly within your XR environment.

  9. Identify breaking changes in Godot XR Tools

    master

    When upgrading Godot XR Tools, be aware of the following breaking changes noted in recent major versions:

    • v4.5.0:
      • Stash sound may not play on scene load.
      • controler was renamed to controller in various classes.
    • v4.3.0:
      • Added support for swapping held items between hands.
      • Added support for two-handed grabbing.
    • v4.2.0:
      • Added support for passing user data between staged scenes (with default handling for spawn-points).
    • v3.0.0:
      • Standardized class naming to XRTools<PascalCaseName>.
      • Standardized file naming to snake_case_name.ext.
      • Renamed functions to avoid collisions with Godot 4.0.
  10. Implement pickable objects using Object_pickable.tscn

    master

    The Object_pickable.tscn scene serves as a base class for creating interactable objects. The demo showcases two ways to extend this base:

    1. Sphere/Ball Interaction

    By inheriting from Object_pickable.tscn and adding a sphere mesh and collision shape, you can create objects like grab_ball.tscn.

    • Visual Feedback: Use a grab-highlight (a yellow highlight sphere) that shows/hides when the object is interacted with.
    • Remote Grabbing: Configure the object for remote-grabbing to allow players to pick it up easily.
    • Collision Behavior: When not held, objects on the object layer (Layer 3) should collide with static_world, dynamic_world, object, held_object, player_hand, and player_body to allow for realistic interactions like hitting or kicking.

    2. Cube Interaction

    By inheriting from Object_pickable.tscn and adding a cube mesh and collision shape, you can create objects like grab_cube.tscn.

    • Visual Feedback: Use a highlight-ring to indicate when the object is available to be grabbed.
    • Collision Behavior: When not held, objects on the object layer (Layer 3) should collide with static_world, dynamic_world, object, held_object, and player_hand (allowing the player to push them around).
  11. Use interactable objects with pickup functions

    master

    The godot-xr-tools library provides various interactable object types that respond to the pickup function on XR hands. To create interactive elements in your scene, use the following specialized nodes:

    • Joystick: Use XRToolsInteractableJoystick.
    • Slider: Use XRToolsInteractableSlider.
    • Lever: Use XRToolsInteractableHinge.
    • Wheel: Use XRToolsInteractableHinge.
    • Button: Use XRToolsInteractableAreaButton.
  12. Explore the Climbing and Gliding Demo

    master

    The climbing_gliding_demo scene serves as a practical demonstration of several movement and environmental providers within Godot XR Tools. It uses a canyon environment with cliffs and updraft wind areas to showcase how these systems interact.

    Key features demonstrated in this scene include:

    • Direct Movement: Basic locomotion.
    • Turning: Rotation mechanics.
    • Jumping: Vertical movement/leaping.
    • Climbing: Interaction with vertical surfaces.
    • Gliding: Aerial movement mechanics.
    • Wind: Environmental forces that affect movement (e.g., updrafts).