banner
YZ

周周的Wiki

种一棵树最好的时间是十年前,其次是现在。
zhihu
github
csdn

Using VRTK for Basic Roaming and Controller Ray Functionality in VR Development

Using VRTK in Unity to Implement Controller Raycasting and Roaming Functionality#

@[TOC](Table of Contents)

By studying the new examples provided by VRTK, namely 【002-Pointers StraightPointer】, 【003-Pointers BezierPointers】, and 【004-Locomotio Teleporting】, I have achieved the functionalities I needed in the early stages.

Description of the 【002-Pointers StraightPointer】 Example#

In this scene, a straight line appears when you touch the touchpad. Pressing and releasing the touchpad will select the object that the ray touches, and you can see the object's border color change. At the same time, the name of the selected object, the distance between the controller and the object, and the position of the ray's tip on the object will be printed in the Unity console.

Description of the 【003-Pointers BezierPointers】 Example#

In this scene, when you touch the touchpad, the controller emits a curve. Pressing and releasing the touchpad will select. You can see three option tiles in the scene; selecting the left tile will change the ray to linear, while selecting the right tile will change the ray style to a custom style. In this scene, the custom style changes the ray's tip to a halo after contacting the object. Selecting the middle tile will set the style to the default Bezier curve style.

Description of the 【004-Locomotio Teleporting】 Example#

In this scene, pressing the touchpad emits a ray, and releasing it allows you to teleport to the position of the pointer cursor. You can teleport a cube onto a rock surrounded by a mesh collider, with no height restrictions. Additionally, a script is used to restrict the gray cube from being a teleportation location.

You can experience and learn on your own.

For convenience in later interactions, my personal development habit is: the left controller emits a curve for teleportation, while the right controller emits a straight line for interaction. I have already set up the basic environment for VR development; if you don't understand, you can refer to my previous articles. Below is the development implementation for emitting rays and teleportation.

  1. Add an empty object under 【VRTK_Scripts】 and name it 【PlayArea】. Add the VRTK component 【VRTK_DashTeleport】 (I personally prefer this one; there are many scripts for teleportation, so learn to use it on your own):
    Insert image description here
  2. Add the component 【VRTK_ControllerEvents】 (script for listening to controller events), 【VRTK_StraightPointerRenderer】 (script for emitting straight lines, which allows changing ray styles and colors), and 【VRTK_Pointer】 (for rendering the ray pointer) to the controller. Drag this object in as shown below:
    Insert image description here
  3. Similarly, add 【VRTK_ControllerEvents】, 【VRTK_BezierPointerRenderer】 (this is the script for emitting curves), and 【VRTK_Pointer】 to the left controller:
    Insert image description here
    Here, to make the pointer cursor look better, you can set it as shown in the image below:
    Insert image description here
    You can also learn to create your preferred style. This completes the basic configuration.

Function Testing#

The controller emits rays for roaming; here, I am using an emulator. Press and hold the 【Q】 key on the keyboard to emit a ray, and release to teleport:
Insert image description here
Left controller emitting rays for roaming:
Insert image description here
The basic functionality has been implemented; I will improve it further later.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.