Press "Enter" to skip to content

Bringing Pokemon magic to Xamarin iOS with ARKit

I loved the Pokemon Go game since it came out, it got me a bit curious about Aumented Reality. So recently I decided to experiment a bit with iOS ARKit in Xamarin.

My adventure started by getting a few 3d models of pokemons from www.clara.io with the idea of creating a simple proof of concept to show some Pokemons, throw a Pokemon ball and do some sort of animation when Pokeball is thrown.

To achieve this used:

  • ARKit: To handle our AR session, bring to life our pokemons and pokeballs, as well as tracking and handling their position relative to the real world.
  • SceneKit: To create our Pokemons and Pokeballs
  • PhysicsKit: To handle our Pokemons and Pokeballs bodies behaviours.

So let our journey begin!!!

First, we set the delegates we will be using to handle the AR session and our physics world.

Let's add some Pokemons

Created this handy method to create our Pokemons from the 3d model files.

Bring them to life by adding them to our SceneView.

In the above block we just enabled some ARKit debug options, run our session and bring Charizard, Pikachu, Bulbasaur and Scyther to scene!

Adding our Pokeball

By detecting touches and getting the camera position we added our pokeball with an applied force.

Let's have some fun with physics

We defined the following enum for handling the physic contact between the pokeball and pokemon.

public enum BitMaskCategory
{
        Pokeball = 2,
        Pokemon  = 3
}

By using a SCNPhysicsContactDelegate we can know when our Pokeball and Pokemon reach into contact so we can play our animation, which is simply to shrink the Pokemon for one second and then get it back to normal scale in two seconds.

That's it! we got our Pokemon magic with just a few lines of code.

Combining SceneKit and PhysicsKit with ARKit is so powerful but at the same time comprehensive and easy to use.

You can find the full source code here:
https://github.com/CrossGeeks/ARKitSample

If you want to learn more about ARKit here are some nice references:

https://www.theverge.com/2017/9/20/16329366/ios-11-apple-arkit-best-new-ar-apps
https://blog.pusher.com/animating-3d-model-ar-arkit-mixamo/
https://developer.xamarin.com/guides/ios/platform_features/introduction-to-ios11/arkit/
https://blog.xamarin.com/augment-reality-xamarin-ios-11/
https://github.com/olucurious/Awesome-ARKit
https://www.udemy.com/ios-augmented-reality-the-complete-course-on-arkit

Happy magic!

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *