Previously, we saw how to set up hand tracking, we learned about grab interaction, poke interaction and ray interaction. We also learned about pose detection. If you haven’t checked out the first part of this series, we highly recommend checking it out. In this blog, we’ll see how to create a VR drawing experience.
Before we start:
We’ll first download all the required assets and set up the scene for drawing.
With that, the setup of our scene is done. Next, we’ll make the Pencil GameObject interactable.
To make the pencil interactable :
Now that the pencil is interactable, the next step would be to constrain it within the boundaries of the paper.
We need to constrain the Pencil movements in all three dimensions so that the pencil can remain within the boundaries of the paper and also it can be lifted only to a certain height. To do that:
With that, we have successfully constrained the pencil movement. The next step would be to create an Ink prefab that will be used to draw lines.
The ink prefab should be a line renderer whose position and size can be altered to visualize the line as it’s being drawn.
With that, we have created the Ink prefab that can be used to draw. The next step would be to use the Ink prefab and its properties to allow the user to draw when the pencil is touching the paper.
To keep the drawing logic as simple as possible, we’ll create a box collider at the tip of the pencil. When the pencil touches the paper it collides with the mesh collider of the paper and that’s when we’ll be able to draw.
With that, we have created a VR drawing experience using hand tracking. This blog was mainly about demonstrating one of the many applications the One Grab Translate Transformer component has to offer. Since hand tracking is still in its initial stages, we can expect some amount of jitter i.e we’ll not be able to draw a perfectly smooth curve. But nevertheless it’s a cool experience.
If you've enjoyed the insights shared here, why not spread the word? Share the post with your friends and colleagues who might also find it valuable.
Your support means the world to us and helps us create more content you'll love.