Reality Composer is a really easy and powerful tool to create Augmented Reality scenes. In this tutorial you can learn how to create object, animations, custom user actions, use physics and change scenes with Reality Composer.
In this project I will create a house that is built by itself after clicking on the button. After that it will be destroyed after clicking on the same button.
You can check the final project at our Repository.
Let’s have a look at the Reality Composer window:
Tap on empty space and rename our project.
My AR project will have two scenes:
- In the first scene I will create a complex animation of house building. The physics will be disabled, because enabling it makes “magically auto-building house” impossible.
- Second scene will be a copy of the first one, but I will enable physics to destroy it beautifully.
Note: I use two scenes because we cannot change parameters (like physics) in one scene.
1. “Build house” Scene
First task is to create a scene with a button that builds a house when tapping on it.
At the beginning I will create a button. At the top you can see a “+” sign — there you can choose an object and add to the scene. Let’s find “text” object. This text will be a button.
Next I’m going to change text object to make it look like a button
After that I will create a model of a house. It will be situated less than 30 cm height.
The house is created from four customized Boxes and one Cone.
Important: I switched physics type to “fixed” for each node.
Let’s go forwards to the actions. In the first scene I tap on the button and the house is being built “down from the air”. You can do this magic using behaviors.
Behaviors сonsists of actions and triggers — conditions under which actions are performed.
I set the first behavior: “make the house invisible at the start of the scene”. Then I click “add behavior” and choose “custom”.
Trigger is the start of the scene. Action is “hide”.
Then I set “hide” action and choose objects to hide
That was easy. Next behavior will be more difficult. I need to tap on the button, and after that building must become visible and sink down to the ground.
Trigger is ‘tap’. Object for the tap is the button (text node).
Further, the first pillar becomes visible and moves to the ground. After that -second pillar, third pillar, fourth pillar and roof one by one.
One of the actions for the first pillar is “show”.
The second action is “move”.
Then, after choosing an object for move I choose a place move to — vertically to the floor.
Next I combine two actions in one using drag-and-drop.
After that I repeat this behavior for other pillars and cone.
First ‘auto-build’ scene completed.
2. “Destroy house” Scene
Let’s create second scene by duplicating the first one:
First scene ends when the house was situated on the floor, so I move our house nodes to the ground in the second scene and change button name to “Tap to destroy”.
There is one behavior which consists of a trigger (tap on destroy button) and an action (the destruction of the house). To destroy a house I will use physics. So let’s enable physics for each node (except the button) and switch type to “dynamic”.
Then let’s create a “destroy” behavior.
Add a tap trigger:
In actions I select “add force”:
And then I choose an object and set a force vector:
Finally I repeat this for all house parts.
I chose this vector aside the roof.
Next I set velocity to almost 5 km/h.
So, when the Second scene is completed let’s connect it to the First scene.
3. Connecting scenes
So there are two scenes:
And it is needed to connect them. Switch to the first scene and open build behavior:
At the end of sequencing we add an action “change scene” and choose second destroy scene:
Yep, our augmented reality is completed, it can be exported and tested.
There is a file with a .reality extension after exporting:
This .reality file is completed result and can be launched on iPhone. So to test just share the file to your iPhone and launch it.
Also you can check the final project at our Repository.