PRESENTER
Enrico BARACAGLIA
WORKSHOP #3
Beginners
Introduction to
VR with Unity3D
29 AUGUST 2018
ORGANIZED BY
ESO, Chile
SUPERVISOR
Frédéric VOGT
Overview
1. Create User Interface (UI)
2. Set up VR scene with
SteamVR
3. Handle HTC Vive controller
inputs
4. Guided practical session
a. Transform.Rotate VR
b. Transform.Translate VR
2
Canvas UI
https://docs.unity3d.com/Manual/UICa
nvas.html
Create User
Interface
3
Insert User Interface (UI)
STEPS:
1) UI > Canvas
2) Modify Canvas RectTransform
3) Canvas > Create Panel
4) Canvas > Create 1st Toggle
5) Canvas > Create 2nd Toggle
Create User
Interface
4
Insert User Interface (UI)
STEPS:
1) UI > Canvas
2) Modify Canvas RectTransform
3) Canvas > Create Panel
4) Canvas > Create 1st Toggle
5) Canvas > Create 2nd Toggle
Toggle UI
https://docs.unity3d.com/ScriptRefere
nce/UI.Toggle.html
Create User
Interface
5
5) Create Empty > Add Component > Toggle Group
6) Add : using UnityEngine.UI;
7) Add : if (myToggle.isOn) { //function };
Toggle Group UI
https://docs.unity3d.com/Manual/scrip
t-ToggleGroup.html
Insert User Interface (UI)
Set up VR
scene with
SteamVR
(new scene)
629/08/18 | enricobaracaglia@gmail.com
STEPS:
1) Download and Import SteamVR
2) Import the prefab [CameraRig] and [SteamVR] from
the SteamVR folder
3) Delete the Main Camera from
the Hierarchy because it will
interfere with the [CameraRig]
and its embedded camera.
4) Ready to press play and see
the world in VR!
Note: you need the VR headset for it to
work properly
729/08/18 | enricobaracaglia@gmail.com
Handle HTC
Vive
controller
inputs
Each controller has the following inputs:
829/08/18 | enricobaracaglia@gmail.com
Handle HTC
Vive
controller
inputs
We can access these inputs by following these steps:
// Create a reference to the object being tracked. In this case, a
controller.
private SteamVR_TrackedObject trackedObj;
// Create a Device property to provide easy access to the controller.
It uses the tracked object’s index to return the controller’s input.
private SteamVR_Controller.Device Controller
{
get { return SteamVR_Controller.Input((int)trackedObj.index) ;}
}
1) Create a new C# script called VR_MoveObject
2) Add the following right above the Update()
method:
HTC Vive tutorial for Unity
https://www.raywenderlich.com/792-
htc-vive-tutorial-for-unity
929/08/18 | enricobaracaglia@gmail.com
Handle HTC
Vive
controller
inputs
We can access these inputs by following these steps:
void Awake()
{
trackedObj = GetComponent<SteamVR_TrackedObject>();
}
3) Add the following method right above Update():
1029/08/18 | enricobaracaglia@gmail.com
Handle HTC
Vive
controller
inputs
if (Controller.GetAxis() != Vector2.zero)
{
controller_axis = Controller.GetAxis();
}
else { controller_axis = new Vector2(0, 0); }
4) Now, you have access to the controller and you can
easily read out the input. Add the following inside
the Update() method:
5) Add the variable controller_axis before the
Awake( ) method
public Vector2 controller_axis;
1129/08/18 | enricobaracaglia@gmail.com
Handle HTC
Vive
controller
inputs
The code at this stage should be:
1229/08/18 | enricobaracaglia@gmail.com
Rotate cube
in VR
6) Create a Cube in the scene
7) Now we add some variables to make the cube
rotate in space
//ROTATE
public float rotationalSpeed;
public float rotateHorizonta;
public float rotateVertica;
public GameObject myObject;
8) And we write the function RotateObj() below Update()
public void RotateObj()
{
myObject.transform.Rotate(Vector3.up, controller_axis.x *
rotationalSpeed, Space.World);
}
1329/08/18 | enricobaracaglia@gmail.com
Rotate cube
in VR
9) Insert the RotateObj() function inside Update()
// Update is called once per frame
void Update()
{
if (Controller.GetAxis() != Vector2.zero)
{
controller_axis = Controller.GetAxis();
RotateObj();
}
else { controller_axis = new Vector2(0, 0); }
}
1429/08/18 | enricobaracaglia@gmail.com
Rotate cube
in VR
How can we make the cube rotate
with respect to another axis?
1529/08/18 | enricobaracaglia@gmail.com
Rotate cube
in VR
Does the RotateObj() function take
into account the position of the
user?
Summary
16
In this workshop you learned how to:
✓ Create and interact with a User Interface (UI)
in Unity
✓ Set up a VR scene with SteamVR
✓ Handle some HTC Vive controller inputs
29/08/18 | enricobaracaglia@gmail.com
“
Thanks for listening.
Any questions?
1723/07/18 | enricobaracaglia@gmail.com https://www.linkedin.com/in/enrico-baracaglia-978789100/

VR Workshop #3

  • 1.
    PRESENTER Enrico BARACAGLIA WORKSHOP #3 Beginners Introductionto VR with Unity3D 29 AUGUST 2018 ORGANIZED BY ESO, Chile SUPERVISOR Frédéric VOGT
  • 2.
    Overview 1. Create UserInterface (UI) 2. Set up VR scene with SteamVR 3. Handle HTC Vive controller inputs 4. Guided practical session a. Transform.Rotate VR b. Transform.Translate VR 2
  • 3.
    Canvas UI https://docs.unity3d.com/Manual/UICa nvas.html Create User Interface 3 InsertUser Interface (UI) STEPS: 1) UI > Canvas 2) Modify Canvas RectTransform 3) Canvas > Create Panel 4) Canvas > Create 1st Toggle 5) Canvas > Create 2nd Toggle
  • 4.
    Create User Interface 4 Insert UserInterface (UI) STEPS: 1) UI > Canvas 2) Modify Canvas RectTransform 3) Canvas > Create Panel 4) Canvas > Create 1st Toggle 5) Canvas > Create 2nd Toggle Toggle UI https://docs.unity3d.com/ScriptRefere nce/UI.Toggle.html
  • 5.
    Create User Interface 5 5) CreateEmpty > Add Component > Toggle Group 6) Add : using UnityEngine.UI; 7) Add : if (myToggle.isOn) { //function }; Toggle Group UI https://docs.unity3d.com/Manual/scrip t-ToggleGroup.html Insert User Interface (UI)
  • 6.
    Set up VR scenewith SteamVR (new scene) 629/08/18 | enricobaracaglia@gmail.com STEPS: 1) Download and Import SteamVR 2) Import the prefab [CameraRig] and [SteamVR] from the SteamVR folder 3) Delete the Main Camera from the Hierarchy because it will interfere with the [CameraRig] and its embedded camera. 4) Ready to press play and see the world in VR! Note: you need the VR headset for it to work properly
  • 7.
    729/08/18 | enricobaracaglia@gmail.com HandleHTC Vive controller inputs Each controller has the following inputs:
  • 8.
    829/08/18 | enricobaracaglia@gmail.com HandleHTC Vive controller inputs We can access these inputs by following these steps: // Create a reference to the object being tracked. In this case, a controller. private SteamVR_TrackedObject trackedObj; // Create a Device property to provide easy access to the controller. It uses the tracked object’s index to return the controller’s input. private SteamVR_Controller.Device Controller { get { return SteamVR_Controller.Input((int)trackedObj.index) ;} } 1) Create a new C# script called VR_MoveObject 2) Add the following right above the Update() method: HTC Vive tutorial for Unity https://www.raywenderlich.com/792- htc-vive-tutorial-for-unity
  • 9.
    929/08/18 | enricobaracaglia@gmail.com HandleHTC Vive controller inputs We can access these inputs by following these steps: void Awake() { trackedObj = GetComponent<SteamVR_TrackedObject>(); } 3) Add the following method right above Update():
  • 10.
    1029/08/18 | enricobaracaglia@gmail.com HandleHTC Vive controller inputs if (Controller.GetAxis() != Vector2.zero) { controller_axis = Controller.GetAxis(); } else { controller_axis = new Vector2(0, 0); } 4) Now, you have access to the controller and you can easily read out the input. Add the following inside the Update() method: 5) Add the variable controller_axis before the Awake( ) method public Vector2 controller_axis;
  • 11.
    1129/08/18 | enricobaracaglia@gmail.com HandleHTC Vive controller inputs The code at this stage should be:
  • 12.
    1229/08/18 | enricobaracaglia@gmail.com Rotatecube in VR 6) Create a Cube in the scene 7) Now we add some variables to make the cube rotate in space //ROTATE public float rotationalSpeed; public float rotateHorizonta; public float rotateVertica; public GameObject myObject; 8) And we write the function RotateObj() below Update() public void RotateObj() { myObject.transform.Rotate(Vector3.up, controller_axis.x * rotationalSpeed, Space.World); }
  • 13.
    1329/08/18 | enricobaracaglia@gmail.com Rotatecube in VR 9) Insert the RotateObj() function inside Update() // Update is called once per frame void Update() { if (Controller.GetAxis() != Vector2.zero) { controller_axis = Controller.GetAxis(); RotateObj(); } else { controller_axis = new Vector2(0, 0); } }
  • 14.
    1429/08/18 | enricobaracaglia@gmail.com Rotatecube in VR How can we make the cube rotate with respect to another axis?
  • 15.
    1529/08/18 | enricobaracaglia@gmail.com Rotatecube in VR Does the RotateObj() function take into account the position of the user?
  • 16.
    Summary 16 In this workshopyou learned how to: ✓ Create and interact with a User Interface (UI) in Unity ✓ Set up a VR scene with SteamVR ✓ Handle some HTC Vive controller inputs 29/08/18 | enricobaracaglia@gmail.com
  • 17.
    “ Thanks for listening. Anyquestions? 1723/07/18 | enricobaracaglia@gmail.com https://www.linkedin.com/in/enrico-baracaglia-978789100/