Monday, 28 November 2016
Wednesday, 23 November 2016
Fading In and Out
In my game I wanted to fade the screen in and out to simulate the player closing and opening their eyes at the start and end of each sequence.
I decided to use a sprite texture attached to the canvas and effect its alpha channel. By changing its alpha channel between 1 and 0 I can effect the GUI transparency.
However I quickly realised that standard 2D GUI does not work in VR. This is because VR can not render certain effects including standard GUI.
I found out however you can still use the canvas and 2D sprites for VR. In order to use the fading effect I wanted I had to effect the Canvas Group instead of the texture directly.
I also had to make sure that the canvas was up close to the player camera and also attached to it. This prevented any light or objects still being viable during the fading.
UI VR
Because you cant use standard GUI in VR (Virtual reality) text book UI (User Interface) and HUD (Heads Up Display) is flipped on its head.
Usually the canvas would be used to display the HUD such as menus, buttons, health bars or anything else the game designer feels appropriate. However because the canvas is always in view of the camera the HUD appears static no matter where the camera moves. This in VR can cause issues as static HUDs can cause simulation sickness.
The solution is not to have a standard 2D HUD at all and instead incorporate it into the 3D environment. For instance I decided to have my controller instructions and tutorial displayed on the TV in the environment. I then created a script to cycle through each image to display each step within the game.
The menus was more tricky. I couldn't use standard GUI button creation normally used for games in Unity. Instead I created 3D objects and box collider triggers. I then fire a raycast from the center camera. If the raycast hits the collider then the menu will activate.
However there was an issue with this method. The box colliders were too close together and the raycast would activate all buttons at the same time. I therefore decided to use one large trigger box which covered the entire menu. I then used different buttons on the xbox 360 controller to activate different menus. I created booleans which activate and deactivate when certain menus are activated. This helps prevent multiple menus activating at the same time when a single button is pressed.
For certain menus such as "how to play" I used multiple planes that are slightly rotated to help cover the peripheral vision, as well as help the player naturally look around.
For the pause menu in the main level I freeze the gameplay every time the game is paused. I make sure the game play is unfrozen both when resuming and when the player returns to the main menu. This not only helps the in game animations to continue, but also allows the light to bake as well.
I also used the fading script I created earlier but made the alpha freeze at 0.5. This helps tint the background making the menu more viable. I'm also playing a risk by attaching the pause menu HUD to the camera and therefore making it static. My hope is that the player wont be in the pause menu long enough for them to develop simulation sickness.
Controls
Controls was very tricky to figure out especially in VR. Because I'm planning on using an xbox 360 controller as my peripheral as well as the Oculus DK2 headset the character controller needed to be modified.
The main issue with using the xbox 360 controller for any VR experience is the camera stick. If the player uses the camera stick on the controller it will contradict the motion input from the headset. With two peripherals both trying to take control of the camera can cause simulation sickness very quickly.
For a while I couldn't solve this issue and considered changing the gameplay from walking simulation to just a sitting VR experience from the center of the room.
However after going to a nDreams VR talk and speaking to Patrick O'Luanaigh he helped explained that I should turn off the camera stick function entirely and use the xbox triggers to rotate the avatar or code a teleportation system to simulate walking.
I decided to use the xbox triggers to rotate the avatar. I set the rotation on the oculus character controller to 0 and added my own rotation script which allowed the triggers to rotate the player.
I also made sure that the whole character controller was switched off as well while the player is rotating. This is because after play testing it myself and to others I found that rotating while moving causes simulation sickness.I also reduced movement speed which also helps tackle simulation sickness.
Triggers
The first steps I took when I started to build the game mechanics is to start simple. I therefore focused on basic triggers. I also used a first person character controller as I wanted to make sure that my game worked as an FPS before I tried to add VR features.
I used trigger boxes to activate events within the game. The first event I wanted to create was a respawn sequence. I decided to use a similar approach from past projects for this.
I made sure once the player enters the trigger their transform equaled to the transform of the respawn location. This code was simply player.transform.position = respawn.transform.position.
I set the respawn position as a trigger box within the baby crib (Small cube trigger) so that the starting point was always in the crib. However this posed an issue on how the player was going to get out of the crib.
I therefore created another script and trigger at the end of the crib which when the player enters and presses a key or button the transform of the player will translate on the y axis allowing them to jump out of the crib. Once the player leaves the trigger box the transform will default back to zero and the player will stop rising. I used a boolean to detect whether the player has entered the trigger or not.
For the majority of the scripts as well as the climbing script I used a combination of booleans and coroutines. When the player enters a trigger the trigger will activate a boolean. Inside the coroutine there will be functions that will activate such as lights turning on and off or animations playing. Some functions can be called after a certain period of time using waitforseconds. Then I'll start the coroutine if the both the boolean equals true and the button or key is pressed.
Picking Up and Throwing
I want to include a picking up and throwing mechanic in my game. However due to my current programming knowledge this is easier said than done.
I used the same teleport code for respawning for my pick up objects. I attached the target area to the main camera so that the object will always move in relation to the camera. I also made sure that the object is also parented to the target area, so that I can attach the the collected object to the target area.
When the player drops the object the object is no longer parented to the target area and therefore can fall and land anywhere in the 3D space. This is where the issues arise. The dropped objects have the habit of either floating in space or falling through objects. Also on some occasions collected objects can clip outside the environment when the player turns the camera. Then when the player drops the object it will continue to fall through space.
I've tried solving this issue by creating a trigger on the floor. When the object is on the floor the gravity on that object is turned off. This prevents the possibility of the object falling through the floor. I then turn the gravity on when the player drops the object. That way the object can fall towards the floor and when it reaches the floor the gravity will turn off.
I've also made sure there are object colliders on the walls of the environment, but they do not stop objects leaving the environment 100% of the time. This is when the throwing mechanic becomes a nightmare.
I still haven't solved the throwing mechanic issues. For reasons I believe to be related to the VR camera mechanic objects cannot identify which direction the camera is pointing. The code allows the object when the player drops it to use physics to propel forward from the camera. However objects can fly in any direction. They also can either clip through or even get stuck on objects with colliders.
Until I solve this issue I've turned off the throwing mechanic entirely. I've only attached the pick up mechanic to the teddy to allow the player to activate the respawning sequence when done so. The idea is to try and build a sense of comfort and reliability between the player and the teddy.
Subscribe to:
Posts (Atom)














