Week 2: AR Implementation
AR Brick Breaker Implementation
In the second session of MIX1 we were given lab hours to work on our project so we started by adding the images we wanted to use as image targets to the Vuforia Database and we imported them to our Unity project. We added an AR Camera and two image targets. The first image target will be the player, and the other one will be level 1 of the game.
Once we had set up the camera and image targets we proceeded to add the models. The player consists of a paddle that the user will move around to hit the ball. The level 1 consists of a board, some walls, the bricks and the ball. At this point we had all the elements so we tried to run it on our phone devices but this took us a little more time than we expected so we decided to keep working on the weekend.
On Saturday we worked on adding the properties and scripts. We started by adding a collider and a bouncy material to all the walls, the bricks, the ball, and the paddle from the player so every time the ball hits one of these elements it will bounce back. For the base plane we added a normal surface physical material
Once we started running the project we lost the ball since it escaped the room, so we needed to add a script to try to control gravity, what we did is adding two functions to enable and disable kinematic. We wanted to enable kinematic when the target is founded and disabled it when we lose it, so on the Level’s Image Target we added the following:
We also added a rigid body to all the elements, this allowed gameObjects to react to real-time physics such as gravity force. Now we had the ball on the board but it was not working exactly as we wanted, we tried to add a force which made it better but the ball would lose velocity to the point of stopping completely, so we decided to do more research.
Since we had multiple bricks we added the block to the prefab folder so we could copy it as many times as we wanted. We also added an invisible top plane to make sure that all the ball will never get out of the level plane.
The bricks needed to be destroyed when hit by the ball, to do that we added a script with a OnCollisionEnter function, in order to be able to select the ball we had previously added a tag to the ball element.

At this point we had most of the project done but the ball movement was not fully what we were looking for and we couldn’t find out why so we decided to ask our teacher Kasper and fix it next week.




Comments
Post a Comment