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 iHaveReturnd · Jun 10, 2014 at 07:03 PM · parentinglocalposition

Logic Question with position and parenting

Hello,

I'm trying to move a child object of a "room" to be on one of the four walls of the room. The problem I'm having seems to be with the fact that the parent, or room, is scaled to fit a specific space, so for example, 12x6x8 (x,y,z), so when I tried to move the child based on the parent's size/extents with localPosition, it moves the child very far off.

If I manually move it, values like .2 come out to be half the room's size when moving the child, so if I move the child .2 it will be on the wall.

I'm having a hard time figuring out how I can move the child object precisely to the parent's walls when the scale of the room is messing with the localPosition values of the child.

Any tips on this?

Thank you for reading!

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
0
Best Answer

Answer by StewVanB · Jun 10, 2014 at 08:52 PM

I will try to explain how this works.

gameObject.localPosition is based on the parent object's "Perfect Zero"

Let's say that you have a parent object of 16,16,8 scale.

If you want the positive X wall you set the child's localPosition to 0.5

The math is like this: (Parent Object's Zero) + ((Parent Object's Scale) * (Child's localPosition))

So in our example: (0.0) + ((16.0)*(0.5)) = 8.0

This will place the child object's absolute zero at the parent's absolute zero + 8.0 or half of the scale.

Using this principle 0.5 in x,y or z will always place the child object at the edge(wall) or the parent object.

Hope this helps!

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 iHaveReturnd · Jun 10, 2014 at 08:57 PM 0
Share

This fixed the issue I was having, and can now set the objects to the wall properly, thanks!

avatar image
0

Answer by Kiwasi · Jun 10, 2014 at 08:53 PM

Multiple solutions, depending on the exact nature of your set up.

  • Unparent the object, move it, then reassign the parent

  • Assign the parent a scale of (1,1,1) (Model it properly so the dimensions match without scaling)

  • Assign the room at appropriate scale to an empty parent gameObject. Assign the child gameObject to the same empty parent.

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

24 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

Related Questions

How to get localPosition to work on parented object C# 1 Answer

On a twice nested object, how to get the local position in terms of the middle parent space 1 Answer

Set child position and move parents with 2 Answers

parent and .localposition? 2 Answers

Physics.Raycast lagging behind 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