- Home /
How to change the way an object is facing when its rotation is 0,0,0?
I have imported a blender model and I need it to be facing a certain way when its rotation is (0,0,0) so its prefab can be used properly in code. I can't simply rotate it and resave the prefab because then the rotation will no longer be 0,0,0. Is there a way to reset this?
Answer by Bunny83 · Aug 02, 2011 at 09:19 PM
Well that's the reason why i always parent imported models to an empty gameobject. Now you can rotate the model the way you need and you use the empty GO as prefab.
The only other way would be to rotate it the right way in blender. But my method has another advantage: When you have done changes to the imported model-prefab, like adding components, those changes will be lost when you reimport the model. If you create a seperate prefab in Unity and just add the model as child that's no problem. The prefab will even work without the model, the model is just the visual part of your object.
The one drawback is that the script on the new parent now has to "reach down" into the mesh for some things. For example, animation.Play(...
is now the$$anonymous$$odel.animation.Play(...
, with the$$anonymous$$odel=transform.Find("myChild$$anonymous$$odel");
in Start.
Yep, that's right but it's not that bad thing. You should cache the component reference anyway so it doesn't matter if you use .animation / .GetComponent() or GetComponentInChildren() ;)
Answer by BerggreenDK · Aug 02, 2011 at 10:42 PM
When exporting from Blender, we use FBX format. In the Export screen, you have several options on what axis to rotate around etc.
We found out that we could rotate 90 deg around x and get same direction as in Unity.
All our FBX files are a "parent" at 0,0,0, but the children are 270 deg x, as the export seems to encapsulate the rotation.
You could also fix this automatically by coding an Import filter for the Editor. Search for AssetsImport.
3DS$$anonymous$$ax has the same issue -- flipping axis on export merely changes the starting Transform.rotation. If you want to really fix it, in Blender go to EDIT mode, select all verts, and rotate (start to rotate then type the angle, to get exactly 90.) The same trick may work with bones.