Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Jyito · Nov 26, 2018 at 05:56 PM · transform.positionplanetcoordinate-systemparent and childspherical

How to fix child gameobject position in relation to sphere parent transform.

Hi everyone, this is my first question here. I been trying to position some random cubes at runtime( st start function) via script over the surface of a sphere. I have an script that changes from Cartesian coords to latitude and longitude and then fix the upper vector to face out relative to the sphere. The problem is that not all my cubes appear on top of the surface, some of them just get under the surface of the sphere or embedded half way on it. The thing is that the squares at some point are going to represent buildings and the sphere a planet. If I take (in my case) from google map the coords of Google HQ and apply it to a square in my scene and also add an Planet Earth texture to my sphere, the coords match, but if I start adding cubes using known coords from other buildings around the world (for testing) sometimes the cubes get stock between the sphere surface.

The code that I been using for the coords transformation is from: https://unitycoder.com/blog/2016/03/01/latitude-longitude-position-on-3d-sphere-v2/

The hierarchy of my game objects is as follow:

ParentGO -> Sphere -> cube

So, I'm not sure if I might need to give it some sort of offset to the cubes, but that haven't work for my at the moment. Does anyone has a suggestion or see something that i might be doing wrong or missing?

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 ecv80 · Nov 26, 2018 at 11:35 PM 0
Share

I take it that you're aligning your cubes by rotating them, so one possibility is that your cubes origin isn't at the center of the cubes. If that's the case, if you spawn lots of cubes, the ones above the sphere surface should be at one hemisphere, while the ones below the sphere surface would be at the opposite hemisphere. Is that so? Then make sure their origin is at their center before aligning them.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Jyito · Nov 27, 2018 at 01:24 AM

Well I actually do is:

  1. instantiate(cube) where the cube prefab is at 0,0,0

  2. Assign cube as a child to sphere

  3. Get some realworld coordinates from knwon buildings from a csv

  4. Send the CSV coords to the PolarToCartesian(), which return x,y,z

  5. Assign the X,Y,Z to the cube.

  6. Finally fix the upward vector using `Quaternion.FromToRotation(up_Vector, DiffBetweenCube and Sphere) * cube.transform.rotation;

  7. Apply that Rotm to the cube.

So, what you actually mean, is that I need to do the rotation before assigning the position in the above steps?

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 ecv80 · Nov 27, 2018 at 07:36 AM 0
Share

Honestly I can't tell if the rotation is being applied correctly from this line Quaternion.FromToRotation(up_Vector, DiffBetweenCube and Sphere) * cube.transform.rotation;. But what I'm saying is, assu$$anonymous$$g it is, maybe your cube prefabs origin(pivot point) isn't sitting at the center of your cubes, and therefore rotating them is causing them to sit at different heights (and slightly misaligned) in your sphere surface. It's just a possibility for you to consider. Not saying this is what's actually happening.

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

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

Keeping (potentially hundreds) of object's transforms relative to animated counterparts? (Without Parenting) 1 Answer

How to apply point value on local coordinate system rather than world coordinate system 1 Answer

Implementing FPS view into locomotion planet walk 1 Answer

Position of cameras children objects messed up after the game start. 0 Answers

stitch spheriphied terrain-like (6) planes (removing gaps from edges) 6 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