If you want to code the VR robot to draw a red line and are confused about the first step.
Here in this article, we will tell you about the first step in coding the VR robot to draw a red line.
Let’s go!
What Is the First Step in Coding the VR Robot to Draw a Red Line?
The first step in coding the VR robot to draw a red line would be to create an object that draws a line and then add it to the scene. The code for this could look something like this:
import be import math from random import randint def main():
#Create a new scene and set its background color to black scene
bge.logic.getCurrentScene() scene.setBackgroundColor(“black”)
#Add a cube to the scene
scene.addObject(bge.objects )
#Set the size of the cube to 0.5 meters
scene.cube.scale * 3
#Move the cube into position
scene.cube.position
#Make sure the camera can see the cube by setting the view angle to 45 degrees
scene.camera.
How To Create A Virtual Reality Drawing App With Unity 3D And Vuforia?
To make your drawing app work with virtual reality (VR), you need to use some sort of tracking technology. There are two types of tracking technologies available today: optical and inertial.
Optical tracking uses cameras or other devices to track objects in space. Inertial tracking uses sensors on the headset itself to detect motion. This tutorial will show how to create a VR drawing app using both methods.
- Choose “Vuforia” as the target platform.
- Select “Unity3d” as the development environment.
- Click “Next”.
- On the next screen, select “Virtual Reality Supported Platforms”.
- Select “Windows Mixed Reality”.
- Click “Install”.
- Wait until the installation completes.
- Open the Unity editor.
- Import the Vuforia package.
- Click “Import Package”.
- Select “Vuforiasdk-2.0.1.unitypackage”.
- Click ‘OK’.
- Wait until the import finishes.
- Go back to the Unity editor window.
- Open the Assets folder.
- Drag the “Vuforiascreenobject” asset onto the canvas.
- Click “Play”.
- Move around the room.
- Look at the screen.
- If everything works correctly, you should see a green rectangle on the screen.
How To Make A Realistic Drawing App With Unity And Google Cardboard?
In this tutorial, we will learn how to make a realistic drawing app with Unity and Google Cardboard. We will use the Unity Asset Store for our project.
This is an easy way to create your own game without having to spend time learning programming languages like C# or Java. You can also save money by not hiring programmers.
The idea of this tutorial is to show you how to create a simple drawing application with Unity and Google Cardboard.
It is very easy to do and requires no programming knowledge. All you have to know is how to use Unity and Google Cardboard SDK.
Step 1: Download and Install Unity 5.6.4f1
- Download the Unity 5.6.x version from here.
- Extract the downloaded archive file.
- Run Unity.
You may get a warning message saying “This version of Unity has been deprecated”. Please ignore it.
Step 2: Import the Google Cardboard Plugin
- To start working on the project, open Unity Editor.
- Select “Google Cardboard” as the type of project.
- Enter a name for the project.
- Click OK.
A dialog box appears asking if you want to install the plugin. Select Yes.
Step 3: Add the Google Cardboard Scene
Now that the plugin is installed, add the Google Cardboard scene to the project.
- Select “Cardboard Scene” under the “New Script” menu.
- Name the script “CardboardApp”.
- Click “Add Component” and choose “Cardboard Scene”.
Step 4: Add the Drawings
Now that the scene is ready, let’s add the drawings.
- Select “Drawing” under the “New Item” menu.
- Name the item “Drawing”.
- Change the class to “Drawing”.
- Under the “Drawing” component, click “Add Component”.
- Choose “Image” from the list.
- Change the image source to “Assets/Images/drawing.png”.
- Click “Apply”.
Repeat these steps for each drawing you wish to include in the app.
Step 5: Create the Main Menu Screen
- Create a new empty GameObject.
- Name the object “MenuScreen”.
- Under the “MenuScreen” object, drag a “Canvas” into the hierarchy.
- Change its position so that it covers the entire screen.
- Delete all child objects except the “Canvas”.
- Set the background color to black.
Step 6: Add the Buttons
- Create another empty GameObject.
- Rename it “Button”.
- Drag two Rectangles into the hierarchy.
- Position them below the “MenuScreen” GameObject.
- Change their size to 50 x 30 pixels.
- Delete the default material.
- Drag a Box Collider 2D component into both rectangles.
- Set the Is Trigger property to True.
- Click the “Is Trigger” button.
- In the Inspector panel, set the Rigidbody2D component to Kinematic.
Step 7: Add the Textures
- Create a new folder named “Textures”.
- Copy the images.
- Paste them into the “Textures” folder.
- Rename the files “drawing_0.png”, “drawing_1.png”, etc.
- Drag the textures into the “Drawing” prefab.
Step 8: Set Up The Camera
- Create a new camera called the “main camera”.
- Place it above the “MenuScreen” and “Buttons” GameObjects.
- Make sure the “main camera” is selected.
- Open the “Camera” dropdown menu.
- Select “Orthographic”.
- Uncheck “Near Clip Plane”.
- Check “Far Clip Plane”.
- Reset the values to 0.01.
Step 9: Start Drawing!
Let’s write some code to control the drawing process.
- Create a new script called “DrawingController”.
- Drag a reference to the “GameManager” script into the “DrawingController” script.
- Change the class to “DrawController”.
- Click the “Update()” button.
Frequently Asked Questions (FAQs)
How do I make my VR Robot move?
You need to create a Rigidbody2D and attach a controller to it. Then, use the Move function to move your character around.
Why does my character not appear when I run the game?
Make sure you have an Oculus Rift or HTC Vive connected to your computer. If you don’t, then Unity will automatically disable the VR features of the editor. Q: What happens if I close the application while there are still drawings on-screen?
When the application closes, any drawings left on-screen will remain visible until they’re removed manually.
Can I change the colors of the lines drawn by the VR Robot?
Yes, but only after the application has been closed. To change the colors, open the “Prefabs” folder and find the “Drawing” file. Open the “Drawing” asset in the inspector window. Under the “Drawing” section, select the “Line Color” field. Change the value to whatever color you want. Click Apply. Now, reopen the application and start drawing again.
Does the VR Robot work with other types of controllers besides the Oculus Rift and HTC Vive?
No, the VR Robot was designed specifically for those devices. It won’t work with other head-mounted displays (HMD) like Google Cardboard or Samsung Gear VR.
Conclusion
This tutorial shows how to build a simple VR application using Unity 5.6.3f1. You can download the project from GitHub.
We hope that this article was helpful. If you have any queries feel free to reach out in the comments section below.