In this tutorial we’ll show you how to create a laser pointer in your VR scene. To follow along, download the required files.
Set up the controller unit
- Create a new project based on the Steam VR template.
- In the Asset Browser, double-click to open the
- In the Script Data panel, add the key “enable_teleport” and set the default value
- In Flow, add in a Get Unit Bool Data node and a Branch node, connect as below.
- Close the Unit Editor.
Disable the default teleport functionality
- Open up the level flow of the default level.
- Using the globally available variables of the Steam VR template for
wand_1 and wand_2, we’ll now set the enable_teleport to false and true
- Add a Level Loaded and a Delay node and connect to the Set Boolean nodes. Slower computers may require a greater delay amount than .1 but generally, this should be fine.
- Set up all of the required files as follows:
- Copy the Laser Pointer/content/models/laser_pointer folder (found in the project download) to your project/content/models folder.
- Copy Laser Pointer/script/laser_pointer.script_flow_nodes to your project/script/ folder.
- Copy LaserPointer/script/lua/laser_pointer.lua to your project/script/lua folder.
- In Stingray, open project/scripts/project.lua
- and add the line:
- Save and close the file.
Set up the laser pointer functionality
- Now we will add in the laser pointer node, the SteamVR Controller Pose node and the Steam VR Button Node and connect as follows.
- Add a length value in the laser pointer node.
In the root of your project, locate boot.package and add...
... to load the models/textures for the laser pointer.
- (Optional) Using offset, you can adjust the
starting position of the laser. You can also change the projection type
to be contact only, laser only, or contact and laser.
For information on the hit filter or hit types, you can consult the Stingray documentation on Raycast. The laser pointer node uses them in the same way.
You can optionally use your own custom units for the Laser Contact and Laser Unit inputs. Length of the laser unit should be 1 meter for scaling to work properly. Feel free to open the fbx files and experinment.
Output "hit" fires once whenever a new hit has occurred.
Output "Not-Hit" fires once whenever the laser pointer is not hitting.
Output "common out" offers a node pass through.
Distance / Laser Scale is the distance from the Start Position to the "hit" unit or the length (whichever is shorter)
Hit Actor returns the Actor hit by the laser.
Hit Actor ID returns the Actors id hit by the laser.
Hit Normal returns the normal vector of the the surface where the laser makes contact.
Hit Normal Rotation returns the normal rotation of the surface where the laser makes contact.
Hit Position returns the world position of the laser hit location.
Hit Unit returns the unit hit by the laser.
Hitting returns true or false depending on whether the laser is contacting a hit actor or not.
Laser Contact Unit Out passes through the laser contact unit
Laser Unit Out passes through the Laser Unit