Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by MigunovAlex · Mar 30, 2015 at 06:59 AM · 2dgameobjectpositioning

Trouble with positioning

2D project. I have a GameObject which I use like a container. Rect position is middle-center. While the game is going I add some objects inside this container, hovewer the size doesn't change. It is 0px widht and height. I have choosen another way to put it right in the center - I know how many object inside this container also I know width and heigth of them. I calculate whole width and whole heigth then divide it on 2 and calculate new Vector3 position in this way: int horizontalLinesNum = horizontalLines[0].Count; int verticalLinesNum = verticalLines[0].Count;

 float newX = -(horizontalLinesNum*LINE_WIDTH) / 2;
 float newY = (verticalLinesNum*LINE_WIDTH) / 2;
 
 Vector3 newPosition = new Vector3 (newX, newY, 0);
 this.transform.position = newPosition;

I've checked values in debug. It calculates newX = -162; newY = 162; Container appears, but not in posiotion(-162, 162,0). It appears in position(-188.3721, -353.4884, 0);

HOW COME? I can't understand where it got this numbers. I have stucked with this for a three days. It blows my mind. Guys, please help.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Tehnique · Mar 30, 2015 at 07:01 AM

It seems there are other things going on that affect your object position after you set it. You can try to set the position in LateUpdate, so it's the last position setting that happens.

Comment
Add comment · Show 6 · 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 MigunovAlex · Mar 30, 2015 at 09:24 PM 0
Share

I had tried this, hovewer no luck. Function works. It recalculates every time right position, when I use.

 this.transform.Translate (newPosition)

Although I don't increment values of position, It is continue moving every frame.

If I use

 this.transform.position = newPosition;

It appears on the same position as I've described above.

avatar image Tehnique · Mar 31, 2015 at 06:48 AM 0
Share

Is your GameObject parented to another? If it is, the parent object's position will affect positioning. Child position is composed with parent position, so you will get weird results. Also, non-uniform scaling on the object might affect it.

Try:

  1. If you have a parent for your object, set the parent position to 0,0,0 and then check if your object is still moved to a weird position after you move it.

  2. Set your object's scale to 1,1,1

avatar image MigunovAlex · Apr 02, 2015 at 10:05 PM 0
Share

I use a new GUI. So I have a Canvas object on the screen. If I add objects without parent I can't see them, but they have proper coords. Hovewer if I put them inside canvas object they have wrong positions

avatar image Tehnique · Apr 03, 2015 at 08:51 AM 0
Share

Is your Canvas Render $$anonymous$$ode set as Screen Space? Also, read this, it might help with understanding how to implement your scenario.

avatar image MigunovAlex · Apr 03, 2015 at 09:35 AM 0
Share

Thank you for the link. I solved it in this way:

I changed the main Canvas to not have the same size on all devices. So,it has scale 1,1,1 now.

After I added a new GameObject at first it was put not in Canvas in position 0,0,0. After I changed parent, coords were changed to new binded to global coords. Now I set localPosition of GameObject and it is ok now.

Now I am able to move these objects properly on my screen!!!

Thank you!

Show more comments
avatar image
0

Answer by MigunovAlex · Apr 03, 2015 at 12:35 PM

I changed the main Canvas to not have the same size on all devices. So,it has scale 1,1,1 now.

After I added a new GameObject at first it was put not in Canvas in position 0,0,0. After I changed parent, coords were changed to new binded to global coords. Now I set localPosition of GameObject and it is ok now.

Now I am able to move these objects properly on my screen!!!

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

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to cover buttons with game objects? 1 Answer

GameObject positioning in World Space 2 Answers

XBox Controller Angle of Fire Incorrect 0 Answers

How am I supposed to use SetTile( ) on a GameObject's position if its x and y values aren't integers? , 1 Answer

View an array of the transform position/rotation of all game objects with a specified tag., 0 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