Starting off developing the flashlight, we're going to use a flashlight asset. This flashlight asset comes with just a white light game object that emits white light from the top of the flashlight.
Let's walk through what we needed to do with the flashlight object.
1. We needed to add a rigid body component to the flashlight to enable physics.
2. We added a capsule collider so that we can interact with certain parts of the flashlight.
3. We added an empty game object called attached and adjusted it so that it was in the center of the flashlight and making sure that the Z-Axis points where the light comes out from. We do this because when we grab the object, the flashlight will point straight where we want it to instead of up or down.
XR Grab Interactable.
After we set up the things that we needed to set up for a grabbable object in the previous step, we'll now add an XR Grab interactable script to the object. We just need to fill in 2 things:
1. The collider with our previous collider we added in the last step.
2. Attach Transform, which is also in the previous step we added.
The attach transform tells us where the object can be grabbed from and which direction it'll appear in while the collider tells us where the object will rest within our hands.
You can play around with how different objects interact with the hand. In a future blog post, I'll explain how to interact with objects such as drawers and doors. For now, this is a simple idea on how to grab objects.