Book Image

Unity 2D Game Development Cookbook

By : Claudio Scolastici
Book Image

Unity 2D Game Development Cookbook

By: Claudio Scolastici

Overview of this book

<p>Unity is a powerful game development engine that provides rich functionalities to create 2D and 3D games.</p> <p>Unity 2D Game Development Cookbook is a practical guide to creating games with Unity. The book aims to serve the purpose of exploring problematic concepts in Unity for 2D game development, offering over 50 recipes that are easy to understand and to implement, thanks to the step-by-step explanations and the custom assets provided. The practical recipes provided in the book show clearly and concisely how to do things right in Unity. By the end of this book, you'll be near "experts" when dealing with Unity. You will also understand how to resolve issues and be able to comfortably offer solutions for 2D game development.</p>
Table of Contents (15 chapters)
Unity 2D Game Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using groups to rotate FBX files


An efficient solution to dealing with the discrepancy between Maya and Unity is to act on Maya's side and rotate the model on its y axis there. Though, as we write, this problem is going to be solved soon by Maya LT, we offer a solution here that prevents the imported FBX file from acting strangely once they are turned into prefabs in Unity. The idea is to use the so-called "groups" to apply the transformations required and yet get a clean hierarchy for the prefab to appear in Unity. Let's see how to do it.

Getting ready

Open the scene again with the model we used before and be ready to follow our instructions.

How to do it...

In this recipe, we will show you how to use groups and hierarchies in Maya to export a model that will not show its back once it gets imported into Unity. Have the Maya scene open on your screen.

  1. From the outliner panel, select the root node of your model. Be sure that the model is at the 0,0,0 position with 0,0,0 rotation.

  2. With root node selected, press Ctrl+G to create a group in the hierarchy.

  3. Double-click on the newly created group name to edit it and type rot_180 (this is actually just for reference so we know what the group means).

  4. Set a value, namely 180, for the rotation on the y axis in the Transform Attributes panel.

  5. With the rot_180 group selected in the hierarchy, press Ctrl+G again to create another group. Name this group export after double-clicking on the group name in the hierarchy.

  6. Now you can select the export node to export the selection in order to get an FBX file out of this model.

How it works...

By using one group for flipping the model on the y axis and another to make a selection featuring neither rotations nor translations for the export, we made sure that the FBX file won't have any unexpected rotation or position offsets that will affect its behavior once it gets scripted into the code in Unity.

There's more...

Another technique we will only mention here is to use your programming skills and code an AssetPostprocessor class to handle the process automatically.

AssetPostprocessor is a class in Unity, provided with several methods to act on the pipeline for importing assets into Unity.

What one could do is add a custom attribute to the model in Maya, something like turn me 180 degrees on the y axis when imported, and let the AssetPostprocessor class read this attribute and perform the transformation.

You can learn more about the AssetPostprocessor class by checking the scripting reference guide at http://docs.unity3d.com/ScriptReference/AssetPostprocessor.html.