Kanda Players 0.7.0
Loading...
Searching...
No Matches
Overview

We provide systems for handling player interactions that integrates with the Kanda interaction system and supports both VR controllers and mouse input.

Overview

Player interaction systems consist of several key components:

  • Player-associated interactors that can be activated by input
  • Support for both mouse-based ray interaction and OpenXR controller-based point interaction
  • Performance optimization through predictive ghost switching

Setting Up Interactors

Player Interactor Spawner

Interactors are associated with players using the PlayerInteractorSpawner component. This spawner:

  • Creates an interactor instance for the player
  • Attaches it to the appropriate player part
  • Ensures correct ghost ownership for networking
  • Handles cleanup when players leave
public struct PlayerInteractorSpawner : IComponentData
{
public Entity PrefabEntity;
public float3 PositionOffset;
}

Available Interactor Types

We provide pre-configured interactor prefabs in Assets/Prefabs/Interactors:

  • Mouse Ray Interactor: Uses camera-based raycasting for desktop interaction
  • OpenXR Controller Interactor: Provides direct interaction for VR controllers

Input Handling

Interactor activation is handled by two primary systems:

PC Input

The PCInteractorInputClientSystem maps mouse and keyboard input to interaction events:

  • Mouse inputs:
    • Left mouse button → Primary interaction
    • Right mouse button → Secondary interaction
  • Keyboard inputs:
    • Activate button (E) → Primary interaction
    • Q grab button → Secondary interaction
    • Space button → Teleport
    • Movement buttons
    • Panning buttons
    • Sprint button

You can find more details about grabbing on PC in the PC Grabbing guide.

OpenXR Input

The OpenXrInteractorInputClientSystem maps VR controller input:

  • Trigger press → Primary interaction
  • Grip press → Secondary interaction

Performance Optimization

Prediction Switching

We include an automatic prediction switching system for interactables to optimize performance:

  1. Configuration:
    • Access the Kanda Player settings in Project Settings
    • Set the InteractionPredictionRange to define the distance from the player where interactions should be predicted
  2. How it works:
    • Interactables within the prediction range use client-side prediction for responsive interaction
    • Interactables outside this range use interpolation to save processing power
    • The transition between states is handled automatically by InteractablePredictionSwitchingSystem
// Example settings configuration
public float InteractionPredictionRange { get; set; } = 10f;

Implementation Example

Here's how to set up a basic interactor for a player:

// Add interactor spawner to your player prefab
var entity = GetEntity(TransformUsageFlags.Dynamic);
AddComponent(entity, new PlayerInteractorSpawner
{
PrefabEntity = GetEntity(interactorPrefab, TransformUsageFlags.Dynamic),
PositionOffset = new float3(0, 0, 0.5f) // Offset from player
});

Troubleshooting

Common issues and solutions:

  1. Interactions not responding:
    • Verify interactor spawner is properly configured
    • Check that interactables are properly configured
    • Ensure prediction range is appropriate
  2. Performance issues:
    • Adjust prediction range to balance responsiveness and performance
    • Monitor number of predicted interactables
    • Consider reducing interaction distance for better performance