0% found this document useful (0 votes)
26 views25 pages

Module 2 - VR Basics1

The document outlines a virtual reality module (BCM3103) focusing on locomotion, grabbable objects, and socket interactions within a VR environment. It provides step-by-step instructions for implementing features such as snap turning, continuous turning, teleportation, and configuring objects for interactivity. Additionally, it covers customizing hand models and organizing the hierarchy for better project management.

Uploaded by

Ariff Iskandar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views25 pages

Module 2 - VR Basics1

The document outlines a virtual reality module (BCM3103) focusing on locomotion, grabbable objects, and socket interactions within a VR environment. It provides step-by-step instructions for implementing features such as snap turning, continuous turning, teleportation, and configuring objects for interactivity. Additionally, it covers customizing hand models and organizing the hierarchy for better project management.

Uploaded by

Ariff Iskandar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

BCM3103 VIRTUAL REALITY

SEMESTER 2 2022/2023

BCM3103 VIRTUAL REALITY


MODULE 2: VR BASIC [2Hours 30 Minutes]
♦ To continue with this Module, make sure you already have a VR-ready setup with
the Virtual Environment of your choice. Suggested a room size VE
♦ In this module, you’ll learn to implement locomotion so that users can move
around the scene and add grabbable objects that user can pick up and throw
around
♦ At the end of this module, you’ll learn to set up sockets that objects can snap
into

A – VR Locomotion [1 Hours]
Hint: You need to add spaces in the room where VR interactions can take place.
Through this module, you will learn how to set up the ability to turn around in place so
that you can experience the room without physically moving and rotating
In Locomotion Setting, there are TWO (2) options – Snap Turn or Continuous Turn

A1 – Add Snap Turning Functionality


1. Rename the XR Origin to XR Rig. Throughout this module, we will use the
term XR Rig
2. Select XR Rig > In Inspector > Add Component > Locomotion System. Drag
XR Origin Script (from Inspector) into XR Origin (under Locomotion System)
BCM3103 VIRTUAL REALITY
SEMESTER 2 2022/2023

3. This will allow the locomotion system to control the XR Rig whenever we have
any kind of movement provider inside of our component
4. To enable the snap turn – in Inspector > Add component > Snap Turn
Provider (Action-Based) > Drag Locomotion System component into System
(Under Snap Turn Provider)
Turn amount = Degree of turning. 45degree is the middle
turning amount to avoid simulation sickness

Debounce Time = Amount of Time that Unity will wait before


it actually turns you again whenever using the joystick to turn
left or right

Enable Turn Left Right to enable you turning left or right


when using the joystick

Enable Turn Around will turn you 180degree in the opposite


direction if you move your joystick back

5. Save > Play. Test using Device Simulator


BCM3103 VIRTUAL REALITY
SEMESTER 2 2022/2023

You can simulate movement by using T (or left shift) or Y (or spacebar) to
toggle one of the controllers, then A or D to simulate snap turning.
A2 – Add Continuous Turning Functionality
6. Disable the Snap Turn Provider (Action-based) by uncheck the component
7. Add Component > Continuous Turn Provider (Action-based) > Drag
Locomotion System component into the System
System: Locomotion System (Script)

Turn Speed: 40 degrees – 60 degrees. When we hold


the joystick, it will turn around at that speed

8. Save > Play. Test using Device Simulator


You can simulate movement by using T (or left shift) or Y (or spacebar) to
toggle one of the controllers, then A or D to simulate turning
A3 – Add Teleport Functionality
In this module, you’ll learn to teleport anywhere within the specific area

There are few options for Teleportation


i. Teleportation Provider
ii. Teleportation Area – Create a
Teleport area that we can teleport
to
iii. Teleportation Achor – To allow
user to teleport at specific spot,
facing a specific direction
BCM3103 VIRTUAL REALITY
SEMESTER 2 2022/2023

A3.1 – Teleportation Provider


9. Select XR Rig > Add Component > Teleportation Provider > Drag
Locomotion System component into the system

A3.2 – Teleportation Area


To be able to teleport, you need to set up the Teleportation area
10. From _Course Library > Prefabs > Rugs > Add one of the rugs into your scene

11. Select the Rug object > In inspector > Add Component > Teleportation Area
BCM3103 VIRTUAL REALITY
SEMESTER 2 2022/2023

Parameter available under Teleportation Area:


Interaction Manager – uses ‘XR Interaction Manager’ to know what kind of input we are going
to be using

Interaction Layer Mask – Drop down menu shows all the different layers that we can actually
interact with

**helpful when you want to interact with specific objects on the different layer

Colliders - Can add custom collider if you need it. Example like stairs

Custom Reticle – If you want to pop up some ‘targetted’ icon when you point at the Teleportation
Area

Teleportation Configuration

Match Orientation: adjust the orientation of the user when they land on the area

Teleport Trigger – depending on your hardware (Oculus etc – how they equipment
trigger function)

Teleportation Provider – What did we teleport.

12. Drag XR Rig (From Hierarchy) into the Teleportation Provider setting (under
Teleportation Area). Save > Play
BCM3103 VIRTUAL REALITY
SEMESTER 2 2022/2023

Now, when you point anywhere on the rug, the line renderer will turn white, and you
can use the grip button on the controller to teleport there. The grip button is the
lowermost button on the inside of the controller, usually pressed with the middle
finger.
Using the XR Device simulator, you can use T or Y to toggle one of the controllers,
use the middle mouse button to aim your ray, then press G to simulate pressing the
“Grab” button.
A3.3 – Teleportation Anchor
To teleport to a specific spot, facing a specific direction.
Teleportation anchor uses the position of different objects to set the position when
user teleport onto them
13. Go to _CourseLibrary folder > _Prefabs > Rugs > Add more smaller mat
objects into your scene. This will be used as the area that you will be teleport
and move around the room without having to move physically
BCM3103 VIRTUAL REALITY
SEMESTER 2 2022/2023

To understand the use of Teleportation Anchor, you need to understand the Gismos
– Blue arrow is pointing to positive Z of the actual game world. To make it easier to
rotate and move the mat – advisable to set the object into Local

When arranging your mat around the room, you may rotate the mat to set where the
blue arrow is facing towards to. This will determine where you will face after teleporting
to this Mat.
BCM3103 VIRTUAL REALITY
SEMESTER 2 2022/2023

14. We will use the Prefabs advantages to set the Teleportation Anchor to all Mat
at once. Select the Mat > In the Inspector > Prefab – Open > Add Component
> Teleportation Anchor
15. In the Teleportation Anchor Component – By default Teleport Anchor
Transform has selected the Mat that we’ve selected earlier.
16. Now, change the Match Orientation – Target Up and Forward. This will make
sure that we’re standing upright on that platform correctly and pointing
forward in direction that the object is actually facing
17. Autosave the prefabs > Exit Prefabs > Save & Play

You should now be able to teleport to the rugs around the room, re-orienting to the
direction of the rug when you arrive
A3.4 – Customize Reticle
The Line Renderers from your hands change color when you can teleport somewhere.
We can provide more visual feedback to the user with reticles.
BCM3103 VIRTUAL REALITY
SEMESTER 2 2022/2023

18. Go to Assets > _CourseLibrary > _Prefabs > VR > Reticles > Select one of the
reticles that you want to use
19. In Hierarchy > Select one of the Rug objects > In Inspector > Find the Custom
Reticle > Drag the Reticles object into the Custom Reticle setting
20. Save & play. Drag your controller to the Rug and voila! You can visually see
the reticle
21. Try to do it at other mats. Don’t forget to make use of the Prefabs advantages!

B – Grabbable Objects [1 Hours]


You will learn how to configure objects for basic grabbable interactivity in VR. By the
end of this lesson, users will be able to pick up objects in the scene and throw them
around
B.1 - Customize Hand Models
To start with the Grabbable functions, let’s add “hands” to the line renderer

1. In Project > Assets > _CourseLibrary > _Prefabs > VR > Hands > Determine
VR_Hand_ options you prefer
2. Assign model to right hand controller: In Hierarchy > Scene > XR Rig >
Camera Offset > Right Hand Controller > Drag the selected VR_Hand (from
Project) to Model Prefabs (Under XR Controller)
BCM3103 VIRTUAL REALITY
SEMESTER 2 2022/2023

3. Do the same thing to left hand controller: In Hierarchy > Scene > XR Rig >
Camera Offset > Left Hand Controller
4. Save > Play

B.2 - Add Grabbable Objects


5. To do the grab functionality, you need an object to grab. Add ball (or any
objects) to the scene: In Project > _Course Library > _Prefabs > Object >
Sport > Drag any of the object into your scene. Example: Tennis_Ball_Green
6. Add an XR Grab Interactable component to the ball: In Hierarchy > Select the
GameObject (Tennis_Ball_Green) > In Inspector > Add Component > XR Grab
Interactable
BCM3103 VIRTUAL REALITY
SEMESTER 2 2022/2023

7. Once added, you can see that it will automatically add RigidBody component
the the gameObject as well
8. Reposition the grabbable gameObject (Tennis_Ball_Green) in front of the XR
Rig > Save > Run > Test grabbing the gameObject by aiming your ray and
grab it
Using the XR Device simulator, you can toggle a controller with T or Y, rotate it to
point at an object by holding the middle mouse button, then press and hold G to
grab and hold an object

9. It is important to make sure the grabbable object is in the correct scale. You
should now be able to grab the object, hold and release
B.3 - Hide Hands and disable anchor control
Currently, the hand model overlaps the object you’re holding, and you can change
that object’s position in your hand with the controller. This is not optimal for
interacting with the scene
BCM3103 VIRTUAL REALITY
SEMESTER 2 2022/2023

10. Let’s change some setting on the XR Rig > Left Hand Controller > XR Ray
Interactor component

Parameters available in XR Ray Interactor:


Force Grab – Enable this will make you grab the object that far from your hand but interact with the
ray

Anchor Control – Allow the user to move the attach anchor point using the thumbstick. If you are using
the joystick, it is advisable to disable this setting

Selection Configuration – Activate Hide Controller on Select

11. Save > Run. Try using your Left-Hand Controller to grab the grabbable object
BCM3103 VIRTUAL REALITY
SEMESTER 2 2022/2023

12. Apply the same to your Right-Hand Controller


13. Add some physics material to make the ball bounce as in the real world:
Select the gameObject (Tennis_ball_Green) > In Inspector > Sphere Collider
> Material: PhysicsMaterial_Bounce_Medium

14. Save > Play > Did you see when you drop the ball, it’s going through the floor
and not bouncing. Thus, you need to prevent this from happening
15. Select the gameObject (Tennis_ball_Green) > In Inspector > Rigidbody >
Collision Detection: Continuous Dynamic
BCM3103 VIRTUAL REALITY
SEMESTER 2 2022/2023

16. Next, we need to allow the ball’s rigidbody physics to work while in our
hand: select the gameObject (Tennis_ball_Green) > In Inspector > XR Grab
Interactable > Movement Type: Kinematic
17. To smooth the motion of the object: In the XR Grab Interactable > Activate
both Smooth Position and Smooth Rotation properties

B.4 - Grabbable Object with Handle


You have added a ball object that is held at its center and where orientation is not
important. Now you will add an object that will be grabbed at a very particular point
and orientation.
18. Add any gameObject with handle – racket, paddle or bat into the scene: In
Project > _Course Folder > _Prefabs > Objects > Sport
BCM3103 VIRTUAL REALITY
SEMESTER 2 2022/2023

19. Repeat Step B.2 & B.3 to make the new gameObject grabbable
a. Add XR Grab Interactable
b. Enable both Smooth Position & Smooth Rotation to decrease jitter
c. Rigidbody component – select Continuous Dynamic for Collision
Detection
20. Save > Play > Try to grab the Tennis > What did you see?
This is not how we grab the handle in the real world, is it? In XR Grab
Interactable, there is Attach Transform properties that allow us to set the actual
grabbable position.
21. For an object with a handle, we need to create a specific attach point. In the
Hierarchy > Select the new gameObject (Tennis_Racket_Blue) > Right-click
on the object > create Empty gameObject (as a child for Tennis)

22. Drag the Attach gameObject (from Hierarchy) into Attach Transform (Under
XR Grab Interactable). Save and play. What did you see?
BCM3103 VIRTUAL REALITY
SEMESTER 2 2022/2023

23. The Racket is sideways. Now, Reposition and rotate the Attach object so that it
matches the position and orientation your hand model should be when you
grab the new object
To do the reposition of the Attach object, you need to understand the position
of XYZ and how the tennis racket is going to be held in our hand.
First, select the Tenis Racket gameObject > change into Global > Move the
gameObject a little bit higher and rotate the gameObject
Change back to Local > Select the Attach gameObject and see where it’s
pointing

Global
BCM3103 VIRTUAL REALITY
SEMESTER 2 2022/2023

Local
Can you see the difference?
As we can see, the up axis (green arrow) of the Attach gameObject is facing
outwards. We want to make sure; the y-axis (green arrow) is facing upward,
and the z-axis (blue arrow) is facing forward.
To understand better, you can drag a VR_Hand object into the scene and
place it at the handle as to see how we normally hold the racket

The hand
BCM3103 VIRTUAL REALITY
SEMESTER 2 2022/2023

The Attach gameObject


24. Save & play. Readjusting the position of the Attach gameObject to suit you
better

It’s getting better and like a real interaction, isn’t it?


B.5 - Organize your Hierarchy!
You can always use create EMPTY gameObject to organize your hierarchy into it’s
own category.
25. In the Hierarchy > Create EMPTY gameObjects > Rename as “XR”,
“LIGHTING”, “DYNAMIC”, “STATIC” and reset the position to (0,0,0)
26. Drag the gameObjects into their own category. They can either be the child of
the EMPTY gameObject or just right under the designated gameObject

C – Socket [30 minutes]


In this lesson, you will learn how to configure sockets that objects can snap into in
VR. By the end of this lesson, users will be able to hang hats up on hooks - and even
wear hats too!
C.1 - Add grabbable hats to the scene & it’s hook
27. 1st, add hook into your scene. Anywhere on the wall to hook the hats later.
BCM3103 VIRTUAL REALITY
SEMESTER 2 2022/2023

28. Add a few grabbable hats – follow the same instructions as earlier.
a. Add XR Grab Interactable component
b. Make the hats obey physics: Collision Detection – Continuous Dynamic
c. Enable smooth Position & smooth Rotation to reduce jitter
29. Save > Play. Test pick up the Hat. You can also add a mirror in the room! Can
you successfully pick up the hat?

C.2 - Turn the Hook into simple socket


To be able to hang the hat on a hook, the hook will need to behave like a socket.
30. Select Hook gameObject > Right-click > Create EMPTY gameObject >
rename as “Socket”. This Socket gameObject should be a child for the hook
31. Reposition the Socket gameObject so that it positioned at one of the Hook. If
the hook has 3 place to hang the hat, you’ll need THREE (3) socket
gameObjects later
BCM3103 VIRTUAL REALITY
SEMESTER 2 2022/2023

32. Define the trigger detection area for the socket so that the hat ‘know’: In
Hierarchy > Select Socket gameObject > In Inspector > Add Component >
Sphere Collider > Click Edit Collider > reduce the Radius = 0.1 (adjust the
radius accordingly)

33. Activate the Is Trigger to prevent it from colliding with the hats but will be used
to trigger an event. Example: allowed the hat to snap onto the hook
34. In Hierarchy > Select Socket > In Inspector > Add Component > XR Socket
Interactor
BCM3103 VIRTUAL REALITY
SEMESTER 2 2022/2023

35. To enable the hat to snap correctly to the hook, we need to create attach point
to the Socket gameObject which will be used for the interactor: Select Socket
gameObject > Right-click > Create EMPTY gameObject > Rename as Attach
36. Save > Play. What did you see?

By looking at the hat snap onto the hat, it doesn’t act like in the real world.
We need the hat to face downward.
37. In the Inspector for Socket gameObject > XR Socket Interactable > Attach
Transform > Drag the Attach (from Socket gameObject) onto Attach
Transform
38. Just like what we did in B.4, adjust the position of Attach so that when the hats
snap onto the hook, it snaps in proper orientation. The hat snap to the hook
but you’ll need to work around to adjust the orientation
Tips: The local Z axis of the attach point should align with the desired forward
direction of the hat and the local Y axis should align with its desired upward
direction
BCM3103 VIRTUAL REALITY
SEMESTER 2 2022/2023

C.3 - Duplicate the sockets and attach hats by Default


Now that you have one fully functional socket, you can duplicate it for the other
hanging locations on the hook and have the hats start on hooks when the scene
loads
39. Rename the existing socket as Socket1 > Duplicate Socket1 and rename them
as Socket2 and Socket3 > Reposition the Socket to its appropriate position
BCM3103 VIRTUAL REALITY
SEMESTER 2 2022/2023

40. Now, let’s have your hats start on the hook by default: Select one of the
Socket > In Inspector > XR Socket Interactor > Starting Selected Interactable:
Drag one of the Hat gameObject into the properties

41. Save & play. Did you successfully hang your hat?
BCM3103 VIRTUAL REALITY
SEMESTER 2 2022/2023

C.4 - Prevent other objects from acting like hats


You can currently put all objects on your head or on hooks as if they were hats. You
can use Interaction layers to control which objects can and cannot interact with
each other
42. To add new layer for hats: In Hierarchy > Select one of the Hat gameObject
(Hat_Captain_Blue) > XR Grabbable Interactable component > Interaction
Layer Mask drop-down > select Add Layer

43. Add a new “Hats” layer in the first available empty slot. Select
Hat_Captain_Blue gameObject > XR Grab Interaction > Interaction Layer
Mask: Hats
Note: Your hat will not yet be set to that layer. You have only created the layer
at this point
BCM3103 VIRTUAL REALITY
SEMESTER 2 2022/2023

44. Set the “Hats” layer to all hat gameObject

45. Make sure the hood socket can only interact with objects on the “Hats” Layer:
Set each of the hook and head socket objects’ Interaction Layer Masks
property to only the Hats layer

46. And make sure other grabbable objects cannot be used as hats: Select all
grabbable objects (except Hats) > Interaction Layer Mask: Default

47. Save and play.

Screen records your game view and shares your work in Forum.

You might also like