- Home /
Unity - How to make child object's local position zero as default for Fbx file?
I try to create breakable object like in this video: https://youtu.be/CIRuczIvB9A
At first try, I export the breakable object as Obj file, it works great: all child objects' local position is zero.
So with this prefab (Obj model) in my scene, after I break the object, I can re-construct the project by resetting all child objects' local position to zero:
foreach (Transform item in transform)
{
item.localPosition = Vector3.zero;
item.localRotation = Quaternion.identity;
}//Everything works OK with Obj model :)
At second try, I export the breakable object as Fbx file, it doesn't work as expect: The child objects' local position isn't zero.
I think if it works with Obj model file, then there must be a way to make it work with Fbx file. So how to make child object's local position zero as default for Fbx file?
The question I wanna have answer is: why "Obj Model" has child local position zero as default, but "Fbx model" doesn't?
Thanks.
Answer by Kciwsolb · Jun 06, 2018 at 01:29 PM
I use Blender, but you can do this in any 3D modelling software. An objects (0,0,0) position is based on its origin. If you go into your modelling software and select all your objects, then apply location (ctrl + a -> location, in Blender), then the origin of all your objects should move to be at (0,0,0). This means when you export as .fbx and import it into Unity, your child objects will all have a position of (0,0,0), but the geometry will still appear to be offset.
Look at the following image (in Blender, but it's the same idea in any program), notice how the location is at (0,0,0), but the geometry is still offset from the origin (the orange point).
The advantage to this method is that when you reset the position of all your child objects, they will go back to their original formation. So, if you had a breakable box, when you reset it it would look like a box again. I believe this is the behavior you are looking for. I do not use .obj often, but I am guessing (lots of emphasis on guessing) it was doing this for you on export.
Maybe someone who knows 3DS Max can comment the key presses required, or you can just google how to apply location in 3DS Max.
In $$anonymous$$aya, it's pivot point. But I think there is disadvantage: If the pivot point is outside the object, then you can't detect the real position of the object in Unity.
Answer by tormentoarmagedoom · Jun 06, 2018 at 11:20 AM
Good day.
As i understand, when you export the object from your 3D modeling program, the childs get a position that is no 0,0,0 so you can not easy reset its position. Is this?
You have 2 options:
You don't need to have them a 0,0,0 position to reset it. Maybe you need to just store the initial position in a Vector3 variable, and use it when you want to "remake" the ball.
The other object, is to create emptyObjects childs of the ball (lets call them "part"), at 0,0,0. And then make the fragments childs of this empty objects called parts, and move the "part" objects to destroy the ball, so you only need to move the "parts" objects to 00 to recontstruct them.
Bye!
Thank for your answer, I appreciate it, you understand me correctly. So I understand your option 2 like the picture below So it works but it requires me to create too many empty objects. I still want to find a way to make it works like the "Obj model" like I mention in the question.