Relevant ViRSE documentation is linked at the bottom of this page

<aside> 🎓 If you’re attending this course through the Graduate school, this page contains the contents of the first in-person lesson. It could act as a useful reference for you after the session, but please don’t go through the material before the session or you’ll be bored!

</aside>

Lesson Two

Lesson Two Walkthrough

Lesson Two Walkthrough

Advanced Activatables

Last lesson, you learned how to create and configure an activatable button and link it up to toggle the active state of gameobjects in your scene. This gave you a flavour of the ViRSE components and allowed you to achieve some basic interactions without any code.

If you want your activatable to do anything more substantive in the scene, you need to link it up to your own code. Luckily, this is very straightforward!

First, create public methods to be called upon activation and deactivation of your activatable. Not that these could just be one method that would be called on both events. Make sure these methods are in a script attached to some gameobject in your scene, then drag and drop that gameobject into the activatable’s OnActivate and OnDeactivate fields. Now you can select the method you wish to link for each of those events.

The activatable will call your script’s functions automatically when activated and deactivated. Remember, when linking a script to an activatable, it is crucial to drag and drop the gameobject in the scene containing that script into the OnActivate/OnDeactivate fields, rather than dragging and dropping the script directly from the project view.

Public methods, which is this case will be used to control movement of the target

Public methods, which is this case will be used to control movement of the target

The Activatable’s inspector, with the methods linked from the above script

The Activatable’s inspector, with the methods linked from the above script

<aside> đź“ť Exercise One - Controlling the target

FreeGrabbables

In order to create the ping pong gun, you must first learn how to make an object grabbable. This can be achieved by attaching a V_FreeGrabbable component to any gameobject with a Rigidbody. This will allow players to “grab” that gameobject and carry it around. FreeGrabbables have a number of properties, some of which are detailed below:

Our ping pong gun’s FreeGrabbable

Our ping pong gun’s FreeGrabbable

<aside> <img src="https://prod-files-secure.s3.us-west-2.amazonaws.com/4f0e98f6-9e1b-4dfa-9a24-c7a0d1e07d4e/18951595-cafa-4f1a-a7fa-85a148203a4b/V_logo.png" alt="https://prod-files-secure.s3.us-west-2.amazonaws.com/4f0e98f6-9e1b-4dfa-9a24-c7a0d1e07d4e/18951595-cafa-4f1a-a7fa-85a148203a4b/V_logo.png" width="40px" /> To learn more about the various properties of Free Grabbables, check out the ViRSE documentation:

FreeGrabbables

</aside>

<aside> đź“ť Exercise Two - Making a grabbable ping pong gun

Grabbable Activatables

Sometimes you will want a gameobject that is both grabbable and activatable. For example, you might want a laser pointer, a remote control, or a ping pong gun. In ViRSE we call objects with this functionality Grabbable Activatables, and you should think of them as a grabbable that has a special kind of activatable added on top.

To give an already grabbable gameobject the activatable property, you attach a GrabbableActivatable component. This component functions similarly to a regular activatable, except the player can pick it up with left-click (or the grab button on the VR controller), and activate it with the F key (or trigger on the VR controller).

<aside> <img src="https://prod-files-secure.s3.us-west-2.amazonaws.com/4f0e98f6-9e1b-4dfa-9a24-c7a0d1e07d4e/18951595-cafa-4f1a-a7fa-85a148203a4b/V_logo.png" alt="https://prod-files-secure.s3.us-west-2.amazonaws.com/4f0e98f6-9e1b-4dfa-9a24-c7a0d1e07d4e/18951595-cafa-4f1a-a7fa-85a148203a4b/V_logo.png" width="40px" /> To learn more about the various properties of Grabbable Activatables, check out the ViRSE documentation:

GrabbableActivatables

</aside>