Panorama VR video game outsourcing Company: Technology sharing using U3D+CB to make VR games

Source: Internet
Author: User

As Oculus announces January 6 to open the pre-sale, 2016 is likely to become the year of VR games, but a lot of research shows that hand-travel equipment is the key to market growth, SuperData released the report shows that the 2016 Global VR game market size is estimated at about $5.1 billion, Consumer equipment installed in about 38.9 million, with the advantage of price threshold, Google Cardboard and Samsung Gear VR as the representative of mobile VR equipment is likely to become the largest number of users of equipment, may occupy the 2016 virtual reality equipment installed volume of 71% of the share, to 27 million.

Our old friend Ray shows in his blog How to use unity and cardboard to turn a 3D game into a VR game, and at the end of the article, he says, you can even turn the game into AR Games or start from scratch with a new VR game.

Many sci-fi films show the ability to control objects with human will, but so far this is still a fantasy, and there is no technology to achieve this. In this novice teaching blog, you can learn how to use unity to do a virtual reality game, with Google Cardboard to create a relatively simple VR experience, this article is mainly about:

Integrate the cardboard camera into your game, adjust the UI elements to fit the VR mode, make a selectable button in VR mode, and programmatically switch the game in both normal and VR mode while the game is running.

What the hell is Google Cardboard?

In theory, creating a VR experience is very straightforward, and you're not showing a single picture on the screen, but you need 2. Because they come from two cameras that are located a few inches apart, the player sees the left image from the left camera and the right image on the right, creating a depth of field for the game.

Plus, with some nice dynamic sensors, you can detect which direction the user is facing. By combining these with the 3D world you create, you get a very immersive gaming experience. In practice, displaying two images on a high-resolution screen requires very complex hardware, as well as tracking the player's head movements, integrating all functions into a single device, and controlling their weight to avoid being too tired for users to wear them.

However, with the advent of Google Cardboard, every smart machine is likely to collaborate with cardboard, using your phone's screen and sensors to turn them into a VR device, and all you need is some cardboard and plastic lenses.

Start preparing

It's important to note that you may be using the Unity GUI a lot, so if you've never tried this tool, it's best to look at the Unity GUI tutorial. To make your own VR game with Google Cardboard, you need the following tools:

Unity Pro, more than 5.0, a smart machine that can be an iphone 5 iOS device, or more than 4.3 Android devices. What needs to be said is that this article assumes that you are developing VR games based on the iphone.

If you've never used unity and are not familiar with the interface, it's best to read the Unity Tutorial Introduction

So the question comes, first of all, you have to have a cardboard device, how to get it?

Of course, if you do not have cardboard equipment, it is best to buy from the supplier, the price and freight is about $20-30, if you think you are very good at DIY, you can do your own version. When buying cardboard, pay attention to the words V2 or cardboard 2.0, as they are suitable for more phones, including the big-screen iphone 6+, and support user input via buttons.

# #没有Cardboard设备可以吗?

In a way, it is possible that you can still run the game on your device and it will look like this ():

When playing games, if you stare at the screen in the right way, you can also find the sense of VR. If you move your phone, you can control it. Although you can also play this game, but also can see the actual effect of the game, but this experience is ... You know.

To make a long story short, if you don't have the patience to wait for cardboard to arrive, you can still learn something from this article, but, if you have the right equipment, you can study more.

Game Demo:ninja Attack

Devote some time to try this demo, download and unzip this Unity starter project. Next is running unity, on the Welcome screen, select Open-Find the Starterninja folder and open the Ninjaattack project.

In Project Browser, in assets, double-click the Mainscene button and click Play to try this game. In the picture, you are the ninja on the left, and as the monsters appear on the screen, you can click anywhere on the screen to release a ninja star to destroy the monster, and after you kill 20 monsters, you win, but if the monster reaches the red area on the left, you lose.

This game looks familiar, doesn't it? The familiar reader may find that it is actually the game I used to introduce Spritekit and cocos2d tutorials, but the difference is that the game is rendered in 3D. Of course, you don't really see the very cool 3D effect, the game uses God's perspective, so it's always a waste of time to render all the polygon, so you can now find out why this game is perfect for VR.

Getting Started with cardboard

The first thing you need to do is download the cardboard SDK for unity. Next, import it into your project. From the Unity main menu, select the Assets\import package\custom package and select the cardboardsdkforunity.unitypackage you just downloaded. Make sure everything is selected, uncheck the Legacy folder, and click the Import button.

In order to make your game a VR experience, you need some tricks to drag cardboardmain prefab into your scene in the Cardboard\prefabs folder in Project Browser, in Inspector, Give it the same position as your ninja character (5.53,1.13,0.122), and do 90 degrees y Rotation.

What you'll find is that it's slightly higher than the center of the ninja, so you can show that you're looking at his eyes.

Next, select the main camera and uncheck it in inspector, and do the same when you do Raccoon Ninja objects. Now, run the game again in the Unity editor and you'll see something similar to the 3D scene. If you press and hold the Select button while moving the mouse, your camera will rotate as the head moves.

Run your game scene on an iOS device

It's nice to run your game in the Unity editor, but the last time you check it, it can be painful to have a VR helmet with a computer monitor, so we need to fit on the iphone.

Select File\build Settings,ios should have been selected as your default platform, click on Player Settings and then switch to Inspector.

Under the resolution and Presentation menu, set the default orientation to landscape left.

In other settings (other Settings), change the bundle identifier to what your company needs, such as COM. (Your company name). NINJAATTACKVR.

Change the target device to iphone, connect the iphone to the computer, choose Build and run, and then name the output folder, which you can take.

At this point, unity will export your project, then it will automatically open in Xcode, if it is not open, start Xcode and manually open the generated project, run and then try on the phone. When you run the game for the first time, you need a series of setup processes, such as scanning the QR code on cardboard hardware, so that the cardboard SDK can fine-tune the picture based on your device, distance, and so on.

It is important to note that if you are in the process of scanning the QR code when there is a URL open error, you must adjust the info.plist in the Xcode project, the Apple Developer Forum on this issue, interested in children's shoes can be personally consulted.

Then, insert your phone into the cardboard, turn back and forth to adjust the camera view, you can see the relatively good 3D picture.

Make it into a game once again

It's great to see your game world, but for the first time, you'll need to add gameplay to the game, especially if you need to throw a ninja star in the direction of the Ninja, which is the first play you'll be doing.

For the UI, cardboard supports a button that may seem a bit more limited, but it can make more complex interactions if it is combined with the dynamic tracking of the head. In "Ninja Attack", You can detect whether the player has started the VR mode through the Cardboard.SDK.VRModeEnable resource, check whether the button is pressed down with the Cardboard.SDK.Triggered resource at the same time, if these values are right, you will be able to throw the ninja star in the direction of the user facing.

Open your NinjaStarLauncher.cs script and you'll find that it's connected to Gamelogic Gameobject in inspector.

Create a new private variable:

Private Vector3 _vrshooteroffset;

Initialize it in the start () method:

_vrshooteroffset = new Vector3 (0.0f, -0.4f, 1.0f);

Replace update () with the following code:

This will work, so let's look at what update () does:

You first check whether the game is in VR mode and whether the user pressed the button to check the resources on the Cardboard.sdk singleton object.

After this, you can call Launchninjastarfrom () to release a ninja star that you need to use for two parameter:

The first is the Gameobject header file, the cardboard library will be tuned out for you, so it should be pointing to the correct position, and the second is a slight shift so that the ninja star in front of you will look more real, otherwise the ninja star you throw out is like a four-eye movement, Although it looks cool, it feels strange to people.

Since your ninja Star Gameobject has been designed to fly in a specific direction, it will attack in the right direction.

Try again, you can turn your head to the bad guys and win or lose logic still works.

Resolve Game Over Menu

You may have noticed that when the game is over, your character is still on the left side of the screen using the previous game over button. This game uses display canvas to show the game over interface, as is mentioned in Unity's latest GUI tutorial, which always appears at the top of the game window. This tag is suitable for most of the game GUI because it automatically adapts to the top of your screen, no matter what your camera is doing, and it fits very well to different screen sizes.

But in this case, you need a GUI canvas that exists in the game world, partly because it can be rendered better in a 3D environment, but also because you don't want to lock the player's love to the camera. Your players need to be able to look up and down freely so they can see different UI elements, find the most active and then click on the button.

Create a new canvas

Under the Hierarchy menu, select Gameovercanvas, right-click and select Copy, rename to Vrgameovercanvas, which distinguishes it from the original and renames gameovertxt to Vrgameovertxt.

In the Vrgameovercanvas component, change the rendering mode to World Space.

In the Rect transform component, change the position to ( -2.24,1.1,0.07) and then 90 degrees y Rotation

Finally, change the x and Y scale to 0.009, and when everything is done, Vrgameovercanvas looks like this:

You can see from the game view view that the two canvases are roughly overlapping (when the game is not running):

Where do these values come from? Frankly, I'm actually adjusting to myself by cardboard the camera looks pretty good up until now. Sometimes, programming is more an art than a discipline.

Supports two x canvase

Next, you need to change the GameController.cs so that it finds two canvas open and gamelogic gameobject scripts, which are also associated with Gamelogic Gameobject. Add the following two common variables to your class:

Public Canvas Vrgameovercanvas;   Public Text Vrgameovertxt; At the beginning of Resetgame (), add the following code:

vrgameovercanvas.enabled = false; Replace Gameover () with the following code:

public void Gameover (bool didiwin) {Isgameover = true; _didiwin = Didiwin; string finaltxt = (_didiwin)? "You won!": "Too bad"; if (Cardboard.SDK.VRModeEnabled) {vrgameovercanvas.enabled = true; Vrgameovertxt.text = Finaltxt;   } else {gameovercanvas.enabled = true; gameovertxt.text = Finaltxt;}} This shows the correct canvas and text objects, depending on whether you are in VR mode (turn on Cardboard.SDK.VRMode).

After you save the script, you need to assign the correct object to the new common variable. Find Gamecontroller in Inspector, click on the target next to each new variable, then select the Vrgameovercanvas object as your VR game over-over canvas variable and choose the Vrgameovertxt object as your VR Game over txt variable.

It is important to note that you may wonder why it is troublesome to support two canvases instead of changing the existing one? The reason is that you need to support both the God perspective and the VR mode, so be sure to optimize it.

If you're ready to run the game now, you'll find that the end-of-game interface in VR mode is natural. You can look up and down the different parts of the interface, and now all that is missing is the button again.

Increase gaze input mode

Fortunately, Unity has built ' the camera center point can be used as a mouse when using the World-space GUI canvas, but you need to provide additional scripts to make it available in the VR interface.

First, expand cardboard main\head, find the main camera and rename it to VR main camera. With the Vrgameovercanvas object selected, you should be able to see an event camera, click on the EventSystem item in hierarchy, click the Add Component button, and add the Gazeinpute module script. This script ensures that Unity's GUI system understands how the cardboard camera works.

Check VR mode only, because it is only necessary to run it in VR. Finally, click on the gaze input module Component you just added and select Move up to repeat once to make sure that it can appear in touch input and standalone input mode, which ensures that the gaze input module takes precedence when the game is in progress. When all is done, it should look like this:

Now, you can try it out. This time, when you put the view on the play again button, it will turn green and let you start a new game again.

Play Fine tuning

You may find that this version of the game is a bit difficult to play in VR mode because your perspective is shrinking, so it's easy for the enemy to sneak past you as you look in the wrong direction. Moreover, you cannot quickly change the direction of the aim, you will be affected by the neck speed limit to the game operation. You let players experience VR mode not to punish them, so how do you adjust it? Of course, someone might suggest lowering the enemy's speed.

In the Prefabs folder, select Evilslimeenemy Prefab, then open EnemyMover.cs, add the following code to start (), and then set the speed:

This will make your game easier in VR mode, so players don't get a bad experience by choosing VR mode.

Troubleshoot on-screen fractional display issues

One of the UI problems you need to solve is the score on the screen, which needs to be handled in a different way. Although it still needs to be properly displayed in VR mode, you'd prefer it to be fixed on the camera when you look in any direction.

Select Cardboard Main\head, right-click and select Ui\canvas, rename the new Canvas to Vrscorecanvas, and adjust the rendering mode to World Space, giving it the following values:

Position (0,1,2.5), width 400, height 100, rotation (0,0,0), scale (0.0115,0.0115,1). When you're done, the game looks like this:

It may seem that your text is strangely placed in the center of the screen, but in VR mode, you can see the world is much less than normal, so you should see the score in the game at the edge, you can adjust the position freely, so that it adapts to your phone.

Next, use the text object to show your score, which is similar to the game over approach.

Open the GameController.cs and add a new common variable:

Public Text Vrscoretxt; Next, every time you update scoretxt, you need to update vrscoretxt, in Resetgame () method, add the following code after each update scoretxt:

Vrscoretxt.text = "–"; This line of code is then added to Gotone (), which is also placed after the update scoretxt:

Vrscoretxt.text = "" + _currscore; Save your script, go back to unity, and you'll find Gamecontroller component in Gamelogic can now enter the VR score txt variable, click on the nearby target and select your Vrscoretxt text object.

Experience your game again, and now you can see that the score appears in the upper-left corner and allows you to move your head.

Switching in VR mode

Since your game supports both God View and VR mode, you should give users the option to switch freely, the UI is very intuitive, you just need to add a simple button in God's view mode, so that players can switch back and forth mode.

First, you need to add the switch code, select the Gamelogic in hierarchy, click Add Component, select New script and then name the script Cardboardswapper.

Open and replace the class code with the following:

The most important method in this class is Activevrmode, which is used to activate Cardboard's VR mode. The rest of logic is responsible for controlling multiple gameobject in the scene, depending on whether you are in VR mode and you don't see something in God's view.

You can also see that the switch () is called when you detect the Back button, which is ideal for testing.

You also need to add more logic to the Gamecontroller script so that it can show or hide something when switching modes, open GameController.cs and add this method:

public void Refreshgameover () {

gameovercanvas.enabled = false;

vrgameovercanvas.enabled = false;

if (isgameover) {

Gameover (_didiwin);

}

Save everything and then go back to the Unity interface, select Gamelogic then scroll down to the Cardboard swapper component, assign it a value of 1 for the cardboard object sequence, and then place it in the scene Cardboardmain The Gameobject. This will not only disable your cardboard head to get you back to God camera mode, you can also disable Vrscorecanvas.

For the Mono object sequence, assign its size to 3, then choose Canvas, Main camera, and Raccoon Ninja for your scene, not from assets.

Finally you need to add a button to the user in the God view Canvas to save time, I have done it, in the Prefabs folder.

Push Cardboardbutton from Assets\prefabs to hierarchy so that it becomes a sub-object of your canvas object, making sure its position setting is ( -50,50,0):

At the bottom of your button object, connect them so that when you click on the button you can call Cardboardswapper.switch () method, and you can see how it is done from this animation:

Try your game again, click the button at the bottom right of the screen to switch to VR mode, then switch to God view mode from the button on the cardboard interface. To do this, your VR mode switch is complete.

Now you can make any 3D game in unity a VR game, and just need a cardboard and some plastic lenses, which is a VR game that everyone can experience. The Android version is roughly the same as iOS, and Google's Unity Developer Guide also provides more technical information. Finally, you can even add AR functionality to your VR game.

Go

Finally, you can try all the 3D games in unity to see if you can make the VR experience a success, or this tutorial will allow you to create a new VR game.

Panorama VR video game outsourcing Company: Technology sharing using U3D+CB to make VR games

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.