Browsed by
Author: Chris

Simple Unity Android VR controller setup for Xbox 360 Controllers

Simple Unity Android VR controller setup for Xbox 360 Controllers

It is no longer required to download the Android VR SDK to build a mobile VR game or application for Unity. Instead, you can set your game up in the Unity build settings and make use of UnityEngine.VR.

Creating a simple player controller may be a bit tricky and so I hope this post will save some developers a head ache when it comes to moving a player around with a gamepad in Android based VR projects.

In this setup, I’m using the following:
1 x Android 6.0 Phone
1 x XBOX 360 Wired USB Controller (but you can use any Android VR controller)
1 x Generic Android VR Headset

To begin, it’s important to understand that you have to create a parent and child arrangement of GameObject’s to control a VR player. Whereas generally a simple FPS controller might be arranged with a Camera as a child to a Capsule, with Unity VR you’ll have to child the Camera to a Camera parent Transform and that Camera parent will be a child to your main player. Even more, the Body of the player will have to be a separate child Transform of the parenting Main Player GameObject if your player has a body. Why? This is done to control the movement of the Camera since moving the Camera Transform directly in VR seems to result in odd behaviour/non-functioning movement at the time of this post.

Here is how your basic Main Player hierarchy should look:

Step 2:
Attach a camera to the Camera GameObject.

Step 3:
In your input settings, add two new axes. For the two different Android phones I tested, the Xbox 360 controller I had seemed to map to these axis:

Step 4:

Create a new script and call it SimpleVRController.cs Use the code below then assign the proper transforms in the inspector.

Unity 2D Target Scanner

Unity 2D Target Scanner

Target scanners are essential for any game where you have an enemy mob that actively looks for prey. One way to scan for targets is to cast a circular physics ray based on the radius area you would like to scan.

Below is a quick and helpful intro I’ve put together for anyone who needs a quick and easy target scanner to notify another script via event subscription. It searches for targets based on the tags set through the Unity Inspector.

How to use from another script:

 

Final notes:

This is a simple solution if you only require a few dozen scanners running at a time or less. If you have many more running concurrently then using tags may be slower and I would recommend scanning based on Unity Layers. You can set which layer to RayCast2D on or alternatively, you can set in Project Settings -> Physics 2D and set which physics layers interact with one another.