← Home

Augmented Reality Basketball

Lucas Saechao2021Developer

AR Hoops is an augmented reality application my team and I built in 24-36 hours as a submission for the hackathon SacHacks 2021. The project is written entirely in Swift, using Apple's ARKit and RealityKit frameworks. The user is able to shoot the ball towards the hoop, by swiping upwards on the screen and reset its position in world space by pressing the button on the bottom. We are responsible for the design and model of the basketball hoop. The ball and court is generated in-application.

Interesting Challenges

My team and I took on this project despite none of us having any experience in either Augmented Reality applications, or an extensive Swift background. We're proud that we were able to build working prototype of the app, but we did face some rather interesting challenges along the way.

Thumbnail of the demo

Since none of us either had experience with Swift or augmented reality applications, a lot of time was spent studying Apple's documentation for how to use ARKit/RealityKit. Luckily, Apple's documentation is rather extensive and we were able to set up both the physics engine for the ball, and load in our models to the game.

Lastly, the way that the ball is moved is dependent on the player's orientation to it, and we had assumed that the player would always be facing the hoop, making our swipes dependent on that direction. If you swipe left, the ball would bounce towards the -X axis. However, we hadn't considered “What if the player movesbehind the ball?” Sure enough, standing behind the ball and swiping left didn't move the ball to the left, relative to our position, but towards the -X direction. To solve this, we implemented a distance checker between the ball's position in world-space, the hoop's location in world-space, and the phone's position in world-space. Whichever object was closer to the hoop would determine which direction the ball would fly if swiped left or right. This is because logically, if the player is closer to the hoop than the ball, then the player is behind the ball. Conversely, if the player is further from the hoop than the ball, then the player must be in front of it.