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 Walkthrough
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
The Activatable’s inspector, with the methods linked from the above script
<aside> đź“ť Exercise One - Controlling the target
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:
Drop Setting - This determines the grabbable’s behaviour when it is dropped. Combined with the settings on the Rigidbody, it can be used to make the grabbable freeze in place, return to its original position or maintain its velocity so that it can be thrown.
Attach Point - Think of this as the place on the object that the user should be grabbing it. Items like swords, broomsticks and table tennis bats all have specific handles or hilts, which is where their attach points should be located. Often, the attach point is an empty game object.
It’s worth taking the time to make sure your object has the perfect position and rotation to make the player really feel like they’re holding the grabbable. The y (up) direction of the attach point should line up with the “up” direction of the controller.
Interaction Events - these work the same as activatables and adjustables: trigger your custom methods when certain events take place.
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:
</aside>
<aside> đź“ť Exercise Two - Making a grabbable ping pong gun
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:
</aside>