Hide and Seek VR

Required: Oculus Rift with Touch Controllers


DOWNLOAD - Google Drive


Hide and Seek


1. Introduction

This game is based on finding hiders at 3 different houses and catching them on time. Hiders can be at any spot which is specified by the game randomly. The player can be chased by the parent of the house if she gets angry because of the first found hider. The score of the player will be increased or restarted depending on the mentioned factors.

Hide and Seek can be played from PC with Oculus Rift VR headset and touch controllers, or can be played without it.


2. The Goal of the Game

The goal is to find and catch hiders in each house on time without caught by the parent. Since the game continues forever, getting a higher score as much as possible is the other goal.


The player should avoid getting a collision with the parent. It will reset the player’s current score to 0 and the level also is restarted. If a hider is running, it should be caught before reaches the exit door. It will result in a score reset and level reset. To prevent these facts, the user should use the red bat on the table and hit with it to hiders and the parent. In the PC version, going closer to the targets and using the keys at the keyboard introduced by the game will help.


When the user catches both hiders and avoids the parent, the next level will be loaded with an increase in the score by 2. The next level can’t be the same house on the previous level.


3. Techniques and Algorithms

First of all, the game checks if the player is an Oculus Rift user or a PC user. Based on the result, it displays the VR menu or PC menu. At the VR menu, the player is introduced with a wall text which says “Press any button to start.”. When a button is pressed from Touch Controllers, the first level starts. The first level is always ‘house1’. On PC, the main menu is displayed with options of start and quit.


At ‘house1’, there are 8 places where hiders can hide. Hiders will be hiding in 2 different places with a random object selector. These places can be wardrobes, TV stands, and kitchen drawers. The players can interact with these objects by grabbing them. To make it easier and faster, to open one of these objects, a small grab touch is enough on their handles. If a hider is available in one of the interacted places, this hider will spawn in front of the object with a %50 chance of running to the exit door. Since the hiders and the parent are NavMeshAgent, they will find their ways with a baked surface for navigation with the fastest option. To stop this hider, it has to collide with the bat’s hitbox collider while it has grabbed from grabbable box collider. If it gets stopped, the current score will increase by 1. If this hider is the first one, the parent has a chance to become angry with %50 chance. If it gets angry, it will start to chase the player and if a collision happens with the player, it will result to restart the level and the current score. If it gets a collision with the bat’s hitbox collider while it has grabbed from grabbable box collider, the game object will be destroyed in 1 second.


Figure 1 The Bat Colliders

If the found hider is the second one, it also has a %50 chance to run, yet it won’t trigger the parent. When it is caught, a new level will be loaded with an increase of the current score.

About the other available hiding places, ‘house2’ has 5, ‘house’ has 6. Also, the timer for each level is 70 seconds on VR, 30 seconds on PC.


4. Scripts

The main scripts for this game are Hider.cs, Parent.cs, ObjectBehaviour.cs and LevelStarter.cs. Oculus SDK has been used for OVRPlayerController with LeftHandAnchor and RightHandAnchor for Touch Controllers. OVRGrabbable script from this SDK is used for grabbing objects. LevelStarter script is attached to the GameManager game object and it sets up the new level. Hider and Parent scripts are the controllers for the hider and the parent game objects. ObjectBehaviour script is attached to hiding spot game objects and it is responsible to spawn hiders.


LevelStarter script focuses on VR checking, new level loading, attending hider spots, setting scores, timer, and 3D score.

Figure 2 LevelStarter.cs

At the start, LevelStarter checks if the user is a VR user and disables one of the player game objects based on the result. Then, it sets up the points depending on Player Preferences. After that, it selects randomly hiding spots on objectNum1 and objectNum2. With initializing the timer, it checks if the player is a beginner or not with Player Preferences. If so, the tutorial canvas game object gets activated and it shows the player how to play the game on PC only. In Update(), the timer updates and the current level gets reloaded based on the timer with SceneManager. The high score gets updated with the change of the current score. It also checks if the objectNum1 and objectNum2 are the same or not and updates it if they are. Control of keyboard input for the Esc menu happens here as well. At last, if the points in the current level are 2, the next level will be decided randomly between the next two houses. This script also has addPoint() function which is used by Hider and Parent scripts to increase the current score.


Hider script starts with initializing isRunning integer and calling setupGui() function. setupGui() function creates an instructive message for the player what to do when it interacts with a hider. In an if loop, isRunning integer is checked and if it is 1, animation of the hider set to running animation. In this loop, also the hider’s agent speed is set with the condition of isVR to keep the game in the same difficulty on each platform. After these settings, the agent’s destination is set to the exit door if isRunning is 1. On Update(), the remaining distance between the exit door is checked and if it is less than 0.1f, it restarts the level and the current score loads the same scene again. If the collision entered with the player and input is ‘Q’ on PC, it starts the dying animation for 1 second and the game object gets destroyed with the current score increase. To check if the hider got a hit by the bat, OnTriggerEnter() function is used with the tagged by ‘batest’ game object which is the hitbox collider of the bat. The same procedure happens on bat hit with the ‘Q’ input interaction. The difference is the bat is not available on PC.

Figure 3 Agents

Parent script also has a NavMeshAgent for following the player. This script checks if the hider game object is null or not. When it is not null, StateSelector() function selects if the parent is angry or not with isAngry integer, randomly. If isAngry is 1, an audio source starts to play until the player is caught or the parent game object is destroyed. It also sets willFollow bool to true which is required to setDestination() function initialize. OnTriggerEnter(), if collider is the player, it resets the level and the current points. If collider is the bat, the game object gets destroyed with dying animation.


Hider and Parent scripts also have collision detection to the in-game doors at OnTriggerEnter(). When a collision happens on the doors’ trigger area, they will open the closed door.

Figure 4 Door Handle Grabbable Box

ObjectBehaviour script changes the hiding spot game objects’ behaviour based on VR is present or not. On its Update(), it behaves differently based on the object if it is a kitchen bench drawer or not. Since collision on kitchen bench was hard to collide the player with on PC, edition to Move Object Controller script of Furnished Cabin asset package has been made. If it is a kitchen bench, the raycast of the player is one of the trigger factors. On other objects, collision is enough. These facts and input ‘Q’ spawns the hider with SpawnHider() function which calls CreateHider() function. This function selects if the hider is female or male prefab. Based on this selection, it instantiates the hider in front of the hiding spot game object with predefined position vectors. In VR, grabbing the object’s hitbox collider is enough.


Furnished Cabin asset package’s MoveObjectController and MoveableObject scripts have been modified. MoveableObject script attends objectNumber for selected object’s animation and checks if the user uses VR. If so, attends OVRGrabbable component in children. It also checks if the object is benchDoor or not. MoveObjectController checks the player and the main camera of it. Depending on collision with the player, it looks for the raycast of the player and based on raycast’s point on which object, it uses the moveableObject and it behaves and sets the animation based on if the user is a VR user or not and isGrabbed or not and input ‘Q’ or not.


PlayerMove and PlayerLook scripts are for handling CharacterController movement and First-Person Camera. PlayerMove script takes the user keyboard input and makes simple movement with Character Controller and jumping with a coroutine which uses Character Controller movement as well. PlayerLook script checks the mouse’s x and y coordinate movement and moves the camera rotation based on it.

References