Week 2 - Marker based AR

 The second session, it was for lab hour. After a short discussion, we picked the idea from Tobias that we would develop a block breaker game.

This would be based on two image targets, where one image target would be the level of the game and another the controls for the game.




Block breaker game used as inspiration


After the installation of Vuforia and set up the license, we began by making simple prefabs with similar functions to the original and scripting some basic behavior. We managed to get the image targets working but the ball always fell when we tried to run and move it. Then we figured it out that we should set the gravity of them to 0, so that we can make it possible to control the paddle by moving the image target.



Early prototype

The biggest challenge we ran into was getting everything collide properly. When moving the ball and the paddle to the controllable image target, the ball would get launched underneath the objects spawned on the level image target. We tried various solutions to fix this. The solution that ended up working was to move all the game objects to the level image target. The control image target would then have an empty game object on it with a script, which would change the position of the paddle. Initially this did not work. To get it to work fully we locked the rotation of the ball and paddle as well as give a y-coordinate reference to one of the walls to the paddle. This would make sure that the paddle remains on the same plane as the level as well as ensure that it does not rotate, which would cause the ball to miss the level when launched. 

 

void Update()

    {

        if(detected)

        {

            var newTransform = controllerTransform.position;

            newTransform.y = yReference.transform.position.y;

            paddle.transform.position = newTransform;

            paddle.transform.rotation = Quaternion.identity;

        }

    }

Code snippet for the paddle controller.

From here we implemented the remaining functionality to the game. This included adding a score counter to the UI and adding a scene manager to change scenes when you complete the level. Currently the game only supports winning the game and has no way for you lose the game. This is one the features that are missing which would make it interesting. Another missing feature would be to add a check that the ball cannot destroy any blocks before having been fired, and maybe adding a minimum distance from the paddle to the level.

Current version

To make the game look a little more appealing we added some colors to the blocks. Since the game consists entirely of blocks it is easy to make simple 2d pixel art. The current main level of the game is a pixel are of a slice of pizza.

We also made some changes to the paddle to allow for more control over the direction the ball would bounce. Overall the game would need a few more features before being complete, but current version shows the potential for a fun AR game.  

The source code for this project is available here.

Comments

Popular posts from this blog

Week 6 - Progress of VR Project

Week 3 - Markerless AR