• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by boymeetsrobot · Dec 04, 2010 at 11:31 AM · gameobjectposition

How to changed the center position of child gameObjects / pivot of parent? (Updated)

I am dynamically generating 6 columns and rows of cubes in a loop as children of a gameObject and then setting their transform to parent so I can rotate , move or scale the parent and the children will all move as well. This starts the cube 1 at 0,0 and increments position by cube.x + cube.width. When rotating, this will mean the cubes are moved along the left edge (0,0). I want to make the generated cubes sit at parent.width / 2 and parent.height / 2. Below is an image to demonstrate what I wish to do:-

alt text

Does Unity contain helper methods to adjust the center point of the parent so that the cubes can be moved / scaled on a central point? E.g. centerPoint.x = this.width / 2

Thanks

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image cregox · Jun 05, 2012 at 01:36 PM 0
Share

dupe? http://answers.unity3d.com/questions/262406/how-to-change-the-pivot-to-an-object-in-an-animati.html

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by uhahaha · Dec 31, 2010 at 01:04 AM

Have a look at the following script :

var parentGameObject: Transform; var scale = 0.1; // scale of the cube var gap = 0.01; // gap between the cubes

function Start() { for(var i = 0; i<6; i++) { for(var j=0;j<6;j++) { var cube : GameObject = GameObject.CreatePrimitive(PrimitiveType.Cube); cube.transform.localScale= Vector3.one*scale; cube.transform.position = Vector3(-2.5*scale + (scale+gap)*j, 0, 2.5*scale+ (scale+gap)*i); cube.transform.parent = parentGameObject; } } }

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image uhahaha · Dec 31, 2010 at 01:08 AM 0
Share

Positions are relative to the parent GO, so apply this script to the parent GO.

avatar image
0

Answer by Jesse Anders · Dec 04, 2010 at 08:40 PM

I'm not sure what you mean exactly, but whatever it is you're wanting to do, you should be able to accomplish it by manipulating the Transform.position and Transform.localPosition fields for the parent and child objects (either in the inspector or via scripting) as needed.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image boymeetsrobot · Dec 04, 2010 at 09:12 PM 0
Share

Thanks for the reply Jesse. I have updated the post with an image to make what I am trying to do a bit clearer.

avatar image Jesse Anders · Dec 04, 2010 at 10:47 PM 0
Share

I don't know of any shortcuts off the top of my head (aside from manipulating the positions as described previously). $$anonymous$$aybe someone else will be able to offer an answer though.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Object's sprite and collider are not at same position as transform 1 Answer

Compare Position of two gameobjects and if true, do nothing, help me please! 1 Answer

Different Position (Object position - Mouse Position) 1 Answer

Moving GameObject to various position ? 1 Answer

Initializing Prefab Position 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges