Have you noticed SpaceX and its launches lately? Did you ever imagine what it would be like to shoot your own rocket into the sky? Well, do not imagine anymore!
In this tutorial, you'll learn how to use ARKit to create a simple augmented reality app for iPads and iPhones. More specifically, we will talk about how we can shoot a rocket into the sky and make sure it continues to fly based on World Tracking.
What will you learn?
We will learn to animate 3D objects in the AR world based on real physical conditions. We will also receive help using the [hkTestandAircraftDetectionDetails we discussed earlier.
- mac with macOS 10.13.2 or later.
- Xcode 9.2 or higher.
- A device running iOS 11+ on an A9 or higher processor. Basically the iPhone 6S and above, the iPad Pro (9.7 inches, 10.5 inches or 12.9 inches, first generation and second generation) and the iPad 2017 or later.
- Swift 4.0. Although Swift 3.2 works on Xcode 9.2, I strongly recommend that you download the latest Xcode to stay up to date.
- An Apple Developer account. It should be noted, however, that you do not need an Apple Developer account. With Apple, you can deploy apps to a test device using an unpaid Apple Developer account. However, you will need a paid developer account to place your app on the App Store. (See the Apple Web site to see how the program works before you sign up for your free Apple Developer account.)
Step 1: Download the required assets
To help you understand this tutorial I've created a folder with the required 2D and 3D assets needed for the project. With these files, you can easily follow this guide, so download the zipped folder with the assets and unzip.
Step 2: Set up the AR project in Xcode
If you're not sure how to do so Step 2 in our article on controlling a 3D layer using hitTest to get your AR project in Xcode set up. Give your project a different name. B. NextReality_Tutorial3 . Be sure to do a quick test before continuing with the following tutorial.
Step 3: Import assets into your project
In your Xcode project, go to the Project Navigator in the left sidebar. Right-click on the art.scnassets folder, where you save your 3D SceneKit files and then select Add Files to Art.scnassets. Add the following files from the unzipped "Assets" folder that you download in Step 1 above: "rocket.scn", "fire.scnp", "smoke.scnp", "smoke.png", " spark.png ". (Note: Do not delete the texture.png file that comes with the project.)
Back in the Project Navigator, right Click on the yellow folder for "NextReality_Tutorial3" (or how you named your project) Select "Files to & # 39; NextReality_Tutorial3 & # 39;
Navigate to the unzipped "Assets" folder and select "Rocket.swift" file. Be sure to check "Copy items as needed" and leave everything else unchanged. Then click on "Add".
"Rocket.swift" should be included in your project, and your project navigator should look something like this:
This file will focus on rendering the rocket and the smoke / fire particle system.
Step 4: Turn on Horizontally Plane Detection
Open Class " ViewController.swift "by double-clicking on it. The rest of this tutorial will handle this document. If you want to follow the final code from step 4, just open this link to see it on GitHub.
In the ViewController.swift file, change the scene build line to viewDidLoad () ] method. Change it from:
let scene = SCNScene (called: "art.scnassets / ship.scn")!
To the following (which makes sure we do not create a scene with the old ship model):  let scene = SCNScene ()
Now we activate feature points. Under this line in viewDidLoad () :
sceneView.showsStatistics = true
Add the following:
sceneView.debugOptions = ARSCNDebugOptions.showFeaturePoints
Next, we enable detection of the horizontal plane. Under this line in viewWillAppear () :
let configuration = ARWorldTrackingConfiguration ()
Then add the following:
configuration.planeDetection = .horizontal
This will ensure that ARKit is able to detect horizontal, flat geometric planes in the real world. The feature points allow us to see all the 3D points that ARKit can recognize.
Run your app on your phone and walk around. Focus on a well-lit area on the ground and you should be able to see yellow feature points as follows: