HW: Twisters, User Friendly UIs¶
Due date: 2024-09-11 23:59.
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¶
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.
Let us look at the example in the image below:
It turns out you can! To see how it can be done - start with downloading and running the .apk we have created for you:
This .apk serves as a solution for the homework below. After you complete it, your Cardboard VR experiences will feature meaningful and exciting interactions, enabling you to create outstanding VR projects.
Will you create a killer app by the end of this course? We surely hope so!
Tasks Description¶
Your task is to implement an interaction system that's convenient to use even when your only form of input is the head orientation tracking. The idea is to interact with objects by rolling your head to the left or right. Simple, right?
A good method of interaction should provide feedback to the user so they understand what's happening. Imagine that you have a crosshair like this in the middle of your field of view in VR, visualizing what you are looking at:
Then imagine that when you look at an interactable object, another such crosshair appears, but rotated by 45 degrees and overlapping the other one, looking something like this:
Whereas your own crosshair would rotate if you roll your head, the other one would 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:
If you wish to think of a different way to visualize this interaction, feel free! For the crosshair, it's recommended to download this package, which includes that basic texture, but also a shader which allows it to be always drawn on top of other objects. Feel free to modify the texture or other aspects as you wish, however.
Implementation¶
There are many ways this could be implemented, so if you already know what to do, feel free to do things your way. But if you want a little more guidance, follow the instructions here closely.
Create 2 empty
GameObject
s under Player, let's call these "Crosshair" and "Lock", and create plane
s under them. Planes by default are facing the wrong way, so with this kind of hierarchy we can easily adjust the orientation of the crosshairs. Make sure the planes have their position set to 0 and X rotation to 90 so they face toward the camera. Apply the crosshair texture on these planes. The resulting hierarchy for the player in the scene should look like this:Player -Crosshair --Plane -Lock --Plane -Main Camera
Feel free to adjust the position, rotation and scale of the crosshairs such that they are in the middle of the field of view, facing the player and appropriate size, but note that they will be further modified by the script.
Next, create the script that will drive the interaction. You can attach it to "Crosshair" for example, but the important thing is to have references to the "Crosshair", "Lock" and "Main Camera". This script should do the following:
- Modify the position and rotation of the crosshairs so they're in the middle of the field of view, with one crosshair following the user's head rotation and the other being tilted in a set rotation.
- Calculate the angle between the crosshairs and execute the appropriate function for the interactable object when the angle is low enough.
- Toggle the visibility of the other crosshair depending on if an interactable object is being looked at. If you wish, you can toggle the visibility of both crosshairs.
Feel free to create any kind of interaction you wish using this system! It could be simple like changing the color of something, making something move, or whatever you think of. Note that grabbing is a bit more complex and not recommended to start off with.
Hints:
Hints:
- The Transform.LookAt function is very handy for getting the crosshairs to face the way you want.
- Also take a look at the Transform and Quaternion documentations to find appropriate ways to manipulate rotation of these objects.
- Raycast can be used to detect if an interactable object is being looked at. From
RaycastHit
you can access thetransform
of the object that was hit, and from there, you could for example use SendMessage to call the interaction function on that object. - You can adjust the required angle for the interaction, but make sure the visuals match. One way to reduce the required rotation is to for example make the crosshair roll twice as much as the head in your script.
- Interactions should be prevented from occurring repeatedly when the head is appropriately tilted. You can do this by requiring the head to be straightened to be able to roll to interact again.
Authors¶
Elmeri Uotila, Anna LaValle.
Give feedback on this content
Leave your comments below: