- Home /
Place object at instanciated object center
As you know, an instanciated object has its origin at (0,0,0) and the 'pivot' is set at the corner of this instantiated object. But I need to set this pivot in the center of my instanciated object only using C#. My plan was to have an EmptyObject placed at the center of my instanciated object and would parent it so I could rotate the whole thing from its center and not from the corner. But how do I get the coordinates to the center of my instanciated object? Thanks
no, not on an instanciated object. Object created in Unity Editor have their pivot in center, on position (0,0,0). But my instanciated object has his pivot on the corner, on position (0,0,0)
Could you have the empty gameobject as a part of your prefab that way when you instantiate it the empty gameobject would already be in the center?
Answer by Strixie13 · Aug 09, 2018 at 08:36 PM
Are you importing something from a unity store package? All of Unity's default shapes will have their origin set to the center of the object. Generally speaking origin points are relative to the mesh, not (0,0,0). Unity's coordinate system moves objects from their origin point. So if you had two of the same object with two different origin points and put them both at (0,0,0) they would actually be in different spots. If you do not have access to the 3D file, then just eyeball it and put the empty object near the middle.
Unity does not have a function to calculate the center of a shape. For that you would need to use a 3D modelling program. For example, Blender has ("Set center to geometry") which will put it at the mathematical center of an obscure shape.
Answer by Saga17 · Aug 09, 2018 at 11:41 PM
I AS I said on previous comment I don't import from store package. I guess I'll have to do that; set the center inside previous used program. Thanks
Your answer
Follow this Question
Related Questions
Instantiate objects level with surface 1 Answer
Ideal Dynamic Object Generation Technique 1 Answer
Instantiating an object returns null 0 Answers
Move character's position to middle of object 1 Answer
The gizmo is not at center of object 0 Answers