Barcode Reader
In depth learning on Usable World Objects is found in this course in Motive Academy.
Overview
Demonstrates how to configure a usable barcode reader that shines a light on activation. Uses the Barcode Scanner asset as a base, found here.
Step 1: Scene Object
To start, we’ll add a Motive Scene Object to the “main” part of the scanner since this is the part the user will be using:
Step 2: Pick up the Scanner
Now we want to make the main part of the reader grabbable. Right-click “main” and choose “Make Grabbable” from the Motive menu:
You’ll notice that when you grab from a distance, the grip is far too low on the handle.
Let’s add a grab anchor to fix that:
Assign this object to the Grab Anchor property on the Grabbable:
Add a light that we can turn on when the scanner is being grasped and the trigger is held down. Add a Spot Light like this:
You can adjust the light settings to fit your needs. Note that the light is disabled by default.
Now let’s connect an Action on the Grabbable to turn this light on & off. Connect Grab Trigger Down and Grab Trigger Up to enable & disable the light:
The scanner should now shine a light while the trigger is held down:
Finally we can make this Usable by adding a Point and Shoot action:
See Usable World Objects for more information about Usables. This action fires when the user points at an object and pulls the trigger. It uses a raycast.
We want the raycast to originate from the light source, so let’s set the Raycast Transform:
Step 3: Attach to Base
With these settings, the scanner will return to its base after you drop it, but sometimes the user will simply want to place the scanner back in its cradle. We can achieve this by making the scanner Attachable and making the base an Attachable Receiver.
Right-click on “main” to “Make Attachable”.
Right-click on “base” to “Make Attach Receiver”.
Drag “base” onto the “Attached To” field of “main”. This assigns “base” as the default Attach Receiver for “main”.
Now when you reach to replace the scanner, you’ll see a highlight indicating that you can place it back in the base. However, with this configuration, you’ll likely notice that the highlight flashes on and off. This is because both base and main have been assigned mesh colliders by the Motive builders. Unity does not handle collision detection between mesh colliders very well.
To alleviate that, let’s replace the mesh collider on base with a box collider:
With this in place, the collision detection will be much smoother and the highlight will be more stable.
Related Articles
Configure One Object to be Used On Another
Usable Actions - Point And Shoot