In this lab, we will start a virtual reality (VR) application.
Create a new project in Godot of type Forward called SnailTrail.
Part of this lab follows the online demo:
https://www.youtube.com/watch?v=gbTUNg99lrg
a. Setup
Go to Project Settings, and under XR click on OpenXR and select Enable at the top. Below that, click on Shaders and enable them too. Close the project settings without restarting the editor.
Above the scene editor, click on AssetLib. You may have to click on the button Go Online and search for XR. Click on the first one at the top called Godot XR Tools for Godot 4 and then click to download it, and after that to install it. You can ignore the warnings.
Going back to Project Settings, click on the Plugins tab and enable the plugin. Then click on the General tab and in the bottom right corner, click on Save and Restart.
b. Scene
Once Godot has reloaded, create a 3D node called Root, create a folder called Scenes under res://, then save the scene in that folder as root.tscn. Right-click on the scene and set it as the main scene.
With the Root node selected, press Ctrl-Shift-A to add a scene as a child of this one. In the search bar enter start and add the scene start_xr.tscn. It will create a node called StartXR.
From the Scene menu, create a new scene. Click on Other Node to add a node to this scene, and in the dialog, enter XRorigin in the search bar. Select the type XROrigin3D. Then add a node of type XRCamera3D as a child of it. Save the scene as player.tscn.
Add another child of the XR origin node of type XRController3D. This will connect to one of the hand-held controller. Rename it LeftHandController. In the Inspector, under Tracker, choose the left_hand. Add another node of the same kind, also as a child of the origin, and select right_hand for the tracker.
Click on the LeftHandController node and press Ctrl-Shift-A. In the search bar enter lowpoly/left and then select the left glove scene. Repeat the procedure for the right hand. Save the scene.
Going back to the root scene, drag the player scene into it and add it as a child of the root node.
Add an environment and a sun to the scene like we've done in previous homeworks.
c. Testing the Program
If you have SteamVR or another application connecting your laptop to a VR device, launch it from outside of Godot and connect the VR device like you normally do. Then when you come back to Godot, you should be able to run the application and see it in the VR system and interact with the controls.
d. Objects
Download the following zip file and extract the files inside:
Add an object of type StaticBody3D with a child of type MeshInstance3D with a plane for the shape. Set the plane's dimensions as 5 x 5. Add a box collider to it and adjust it to fit the plane.
Add another StaticBody3D object called TableBody. Drag the table.obj and table.mtl files into the project to import the object, then add it to the scene and make it a child of the TableBody object. Resize it so that it's not bigger than the plane. Add a box collider to it and fit it on the top of the table. Set the materials for the ground and the table as you like.
Pull the XROrigin3D object on the vertical axis until it is above the table. Rotate its camera towards the table a little and pull it back on the direction the camera is facing.
With the root node selected, press Ctrl-Shift-A again and look for pickable. Add a pickable.tscn object. Pull it up so that its origin is a little above the table.
Then drag the file snail.glb file into the project and then add the object to the scene. Scale it down so that it has room on the table to move around a little, then make it a child of the PickableObject. Add another child of the pickable object of type CollisionShape3D and set its shape as a box, then adjust it to fit the snail approximately.
e. Pick Function
Click on the tab for the player scene to switch to it. Select the object LeftHand that is a child of the LeftHand controller.Hit Ctrl-Shift-A. Search for pickup and select function_pickup.tscn. Redo the operation for the right hand. This will allow the user to pick up the object in VR and place it somewhere else or play with it.
This is the end of the lab. If you'd like to develop this further and turn it into a project, the snail contains an animation that can be used while it's sliding across the table.
You can submit a Windows build for 5 extra credit points to Lab 11 in Canvas.