Project Part 3: VR Cardboard Interactions¶
Due date: 2026-11-13 23:59.
Have you wondered why interaction is limited in all the Cardboard VR experiences you’ve tried so far? Without 6DOF positional tracking and controllers, Cardboard VR doesn't allow for simulating walking, grabbing, or many other interactions possible with high-end HMDs. Until this homework, that is.... It turns out there is a way to create meaningful interactions, even with 3DOF orientation-only tracking systems.
Before starting...¶
If you haven't done it yet, we recommend setting up version control as a way to help avoid potential problems that could cause you to lose progress. Here is a quick tutorial: GitHub Desktop for Unity
Interactions in 3DOF VR¶
Let us look at the example in the image below:
It turns out there are more ways than previously thought! We have defined four basic Cardboard interaction methods for you: Twist, Dwell (also known as gaze input), Press and Hold.
Twist refers to, well, twisting your head - rotating it on the roll axis until a certain angle, at which point an action is triggered. In this case, picking up or dropping the cube. To see how it can be done - start with downloading and running the .apk we have created for you:
Dwell means looking at an interactable object until a timer completes, at which point some action is triggered. It is the "classic" 3DOF input method, used in many applications.
Press utilizes the trigger button found on the side of the Cardboard. It uses a conductive strip to touch the screen to register an input. Finally, Hold is an extension of press, where holding the trigger down for a set time causes an action to be executed.
Beyond the basics, your imagination is the only limit. You could combine or modify the former interactions to form new ones. Other input methods, such as utilizing the smartphone microphone or camera, are also possible for those who want the extra challenge.
User Friendly UIs¶
A good method of interaction should provide feedback to the user so they understand what's happening. Let's take the Twist for example. First, to visualize you are looking at an interactable object, a double crosshair like this appears in the middle of your field of view in VR:
The first crosshair will rotate if you roll your head, the other one will not. And so, to interact with this object that you are looking at, you must make the crosshairs line up by rolling your head:
In VR, it could look like this:
Implementation¶
While anyone could implement this from scratch, we are providing you with a Unity package that you can import to your project. This package includes the four basic interactions. Get it here:
To use this package, you can either drag and drop it to your project assets view in the Unity editor, or right click empty space in that view and choose the
Import Package option from the context menu. You should then get a prompt to choose which files to import from the package, so make sure to import them all.
After that, you should have a
CardboardInteract folder in your assets. From there, drag and drop the Interactor prefab on the Main Camera in your scene. There are some options in the inspector for that prefab, but you can leave them as they are for now, but make sure the position and rotation of Interactor is all set to 0! Remember to disable the old CardboardReticlePointer.
Now, all that is left is to add interactable objects! For a simple test, add the included
Interactive script to an object, then play the scene in the Unity Editor and manipulate the rotation of the main camera through the Unity inspector to perform the twist interaction on the object, and there should be a message in the Console view!In order to create your own interaction, you must create scripts that inherit
Interactive. You can do this by creating a script as you normally would, such as by choosing Add Component in the inspector when you have an object selected in the scene that you want to make interactive, and typing a name you want to give and selecting New script. After this new script is added, open the script in Visual Studio or another editor of your choice (by double clicking the script name in the inspector or in the assets view). In the script, change the MonoBehaviour to Interactive, as that is where it's defined what class is inherited.
In order to add your interaction logic, create a function
public new void Interact() which will override the print statement we tested earlier. This function will be called when the user interacts with this object. You can fill this function with any interaction logic you want! Make the object jump, change color, whatever you want. Feel free to also add any other function, and you can use the Unity default Update and Start functions too if you want.
Assign the
Interact Mode Override in the Editor to select which interaction method you want this object to use.You can also assign overrides for the Twister angle and Dwell timer. This is useful if you want different interactions to have different sensitivity to trigger them. For example, teleporting using the Twist should have a lower sensitivity than selecting something. You can also change the default parameters in the CameraInteract component. Press and Hold parameters can also be changed in the TriggerInteract component, but not per-object.
Teleporting and Grabbing¶
The package has now been updated with teleportation and grabbing scripts. These are not required, but will be helpful in creating a more interactive project!
In order to use teleportation, add the
TeleportSurface component to the floor. It is recommended to create a new Plane for this purpose so the teleportation area is bound to other geometry. You can delete the Mesh Renderer from this new object. This way, we can define the teleportation area without affecting the visuals. Make sure the plane is on top of other colliders, or make use of Layers to bypass other colliders. For teleportation using Twist, consider adjusting the Twist Multiplier Override to something lower than default, such as 4, if you feel like accidental teleportations might be a problem! Also, once again, make sure the position and rotation of Interactor is all set to 0 for any of this to work correctly!As for grabbing, simply add the
Grabbable component to an object that you wish to be grabbable, and make sure that object has both a collider and the Rigidbody component. You can now for example twist to grab the object and twist again to let go! Try adjusting the Grab Speed to control how quickly the object follows your gaze, and set whether the object should use gravity here (gravity is always off while grabbed, so it needs to be controlled here). You can even throw objects by giving them some momentum right before letting go!Global Trigger¶
The
TriggerInteract component is slightly different from CameraInteract in that it can register input regardless of whether the player is looking at an interactable object. This allows you to define a separate action for trigger presses that aren't targeting an object. Unlike object-specific interactions however, this action is global, meaning the same logic is executed for all such trigger presses. You can define these actions yourself in the GlobalTriggerPress and GlobalTriggerHold scripts:
By default, the GlobalTriggerHold recenters the Cardboard view after 3 seconds. This is an updated version of the original recentering. To avoid conflicts, it is recommended to delete or comment out the original recentering in CardboardStartup.cs as shown below.
Authors¶
Elmeri Uotila, Teemu Kulojärvi, Anna LaValle.
Give feedback on this content
Leave your comments below: