Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
This question was closed Dec 08, 2018 at 11:19 PM by Feref2.
avatar image
0
Question by Feref2 · Oct 05, 2018 at 05:13 AM · scalingpositioningparenting

Is there a way of correctly parenting to get scales and positions of gameObjects right?

Originally, I was doing this:

 void Update ()
 {
     this.transform.position = new Vector3 (previousObject.transform.position.x + prevRend.bounds.size.x / 2 + rend.bounds.size.x / 2, this.transform.position.y, this.transform.position.z);
     //the position of both gameObjects should be aligned when one or both of their scales change
 }

But because gameObjects didn´t update their positions fast enough (caused gaps for small amounts of time), I thought maybe making something different. So I commented the rest of my doings earlier, which is basically changing the scale of a parent object based on a percentage to make its children do the same. Their positions changed automatically, avoiding the gaps that I had. Also this works with the correct proportions for every gameObject and even the positions are right... when including everything. I wanted to increase or decrease size of some of this gameObjects independently to the others, but when these are out of the parent the positions are not aligned anymore. Is there some way of correctly parenting them and get both things right?

Comment
Add comment · Show 5
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 TreyH · Oct 05, 2018 at 07:37 PM 1
Share
 previousObject.transform.position.x + prevRend.bounds.size.x / 2 + rend.bounds.size.x / 2


Can you expand a little on what you're trying to achieve? There isn't a speed or anything here, and we don't know what those other objects are.

avatar image Feref2 TreyH · Oct 05, 2018 at 10:38 PM 0
Share

Ok, so this gameObjects are like pieces of the ground that I want to keep together when their scale changes. There is no speed because this change in position should be immediate, like the change in position from a parent relation.

avatar image Omti1990 Feref2 · Oct 06, 2018 at 05:44 PM 0
Share

If you want to scale pieces of the ground up and move them? Why don't you just change the scale of the parent object and move its position?

If you change the scaling of the parent you automatically scale the children.

Show more comments
avatar image Feref2 · Oct 07, 2018 at 12:13 AM 0
Share

So apparently, if a parent object has the percentage scale script and has a lot of children with different values, each percentage applies correctly. However, there are some gameObjects that I want to keep the same value until something happens. If those objects are also children, the position does what I want. But because I didn´t wanted them to increase or decrease size like the others, I removed them from the parent. So again, everything has the correct scale, but then their positions are not aligned. Is there some correct way of parenting them and get both things right?

2 Replies

  • Sort: 
avatar image
0

Answer by hexagonius · Oct 07, 2018 at 12:37 PM

there are two ways of doing this:
- keep your objects children and by the time they should be locked to their scale, save the parent scale and keep multiplying the local scale by saved scale divided by current parent scale, which will counter scale the object and therefore keep it's size (works with just one parent that's changing scale only)
- unparent the children by the time they should be locked to their scale, but save their local position beforehand. now you can use parent.TransformPosition(savedLocalPosition) to get the scaled position you can set the childs position to. since not parented, it will keep it's size but move relative to the parent through scale.

I recommend the second option

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 Feref2 · Oct 07, 2018 at 07:25 PM 0
Share

Thanks, but I think I don´t understand what you are telling me to do. I don´t get how works the first option, so I tried the second option and added this script to each constant scale object:

 Vector3 savedPosition;
 public GameObject parent;
 Vector3 scaledPosition;
 public GameObject child;

 void Awake ()
 {
     savedPosition = this.transform.position;
 }

 void Update ()
 {
    scaledPosition = parent.transform.TransformPoint(savedPosition);
    //I used transform.TransformPoint since the TransformPosition wasn´t in the scripting reference
    child.transform.position = scaledPosition;
 }

So as I was saying, I added this script to every base (the constant scale objects) and set the child variable to only the child gameobject next to this one, which didn´t actually cover all the children (since there were 3 bases and 4 children). It didn´t work.

avatar image
0

Answer by Feref2 · Oct 08, 2018 at 06:09 PM

OK, so actually a better solution was just to use InvokeRepeating () to update the position faster avoiding gaps. Nothing related to parenting.

Comment
Add comment · 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

Follow this Question

Answers Answers and Comments

96 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How does Transform.SetParent() worldPositionStays work with null parent? 1 Answer

Weird Positioning Problem? 1 Answer

Colliders scale on parenting and rotation 2 Answers

Object not following parent position when parent rotation is locked,Unable to move an object with its parent when rotation is locked 0 Answers

Converting Pixels to Units and Position Prefab 1 Answer


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