Placing a Target in an Imported Animation
It’s possible that after importing the Harmony animation into the Unity scene, you may want to assign a target to some piece of the animation. For example, in the Space Duck scene, the character has a gun. Perhaps you want to attach some other action, such as shooting spheres and cubes out of the end of the gun.
You can see some examples of this in the provided Unity project. The first example in the demo scene is called DemoLocator which shows a simple cylinder attaching to the end of the gun.
The second example called DemoCallback shows the gun shooting spheres and cubes.
When you set up your character in Harmony, you can access any drawing layer in Unity later and use its pivot point to attach things. For this reason, you should set the pivot points on your drawing layers with the Rotate tool.
You can also create an empty drawing layer. Use Create Empty Drawing to create a blank drawing, ensuring that this drawing layer will be exported. Then you can use the Rotate tool to set the pivot point on this drawing layer. In the Space Duck example, an empty drawing layer called
hook_gun was created on which you can attach the locator.
When you access the imported Harmony character in Unity, you can access the data with a script.
|1.||Select Game Object > Create Empty to add a new GameObject to extract the target's position, rotation, and scale.|
|2.||Drag and drop the new object so that it's a child of the character.|
It becomes indented.
- Rename the GameObject to:
- In the Inspector of the target object, select Add Component > Scripts > Harmony Locator.
- Enter the name of the drawing layer to which you want to attach.
- To find the exact name for the Locator Name, look at the
skeleton.xmlfile in the Streaming Assets folder. You can find it in Streaming Assets > Harmony Resources > Name of Harmony File > skeleton.
All the drawing and peg layers are listed. In this example, look for
space_duck_hook_gun. Having drawing layers with distinctive names makes them easy to recognize when you need to retrieve them.
You can copy the name of the layer into the Locator Name to see the Transform information updating dynamically as you run the simulation.
- Now you can attach anything as a child of this Locator Object. For testing purposes, you could attach a cylinder for example. In a real example, you’d want something to shoot out of the end of the gun, so you can see the Callback example to verify how that works.
Bounding Boxes and Collisions
Extracting the bounding box information is useful when you want to make something collide with your character. When you put a 2D character into a 3D scene, you may want to use Physics to make the 2D character collide with the 3D plane. To use the following scripts, you will need Unity 4.3 or higher.
In the Demo scene, open the DemoPhysics example to see collisions and bounding boxes. In this example, there’s a 3D plane and some 2D characters. The 2D characters have a collision defined with their bounding box, and they're also reacting to the physics of the scene to fall with gravity.
Colliders were improved to provide several different types of colliders for use in Unity. You can select polygon colliders and box colliders for a more accurate bounding box.
- Select your imported character.
|3.||In the inspector, select Add Component > Physics 2D > Box Collider 2D.|
|4.||To enable the Physics on the character, go to Add Component > Physics 2D > Rigid Body 2D.|
You can now adjust the variables and see the results.
Working with Audio
When you create scene files in Harmony with audio, the audio is exported into the project folder. However it’s important to understand how the game is built to determine the best way to handle audio.
When a game is built from Unity, it creates its own database for holding the assets. Within the export, the Streaming Assets folder is preserved intact. This is what enables the Toon Boom plugin to access those assets on the fly, and render them in the camera to create the final animation you see on the screen.
However when it comes to audio, the game first looks for the audio in the Unity database. So this is the most efficient place to store the audio for the real game.
If audio can't be found in the Unity database, then the game looks in the Streaming Assets folder to find the audio. When it does, it copies the audio on-the-fly back into the Unity database. Since this action is quite costly, don’t leave the audio in the Streaming Assets folder for the final game. It’s fine to leave it there while you’re testing, but not for the final game.
The audio should be copied back into the Unity database, either manually or by automating this process with a script.