• 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 smouton123 · May 19, 2016 at 05:23 PM · rotationvector3rotation detection

Align a vector3 with parent's up-vector.

Hi, I'm (very) new to Unity and my vector-math is buried deep in my subconscious, next to my knowledge of 80s music... but I'm sure this question is straight-forward for anyone with minimal experience in Unity/basic-math.

I have a gameObject (a 'gauge-needle'), and I created a behavior-script (c# component) that uses two Vector3 coordinates to represent points at some distance from the gauge-needle. To be precise, the two vectors represent "min" and "max" coordinates for the gauge-needle.

Now, the gauge-needle is parented inside a dashboard-gameObject, which can be moved around... Moving the dashboard also moves the needle, but as you can guess, this doesn't move my min-max vertices.

How may I: (a) detect that the parent's position/rotation are changing?
(b) move my vertices accordingly, so that they follow the dashboard's "up" axis?

I would like to avoid creating gameObjects for the min & max vertices, I don't mind doing the math, I just need someone to point me in the right direction. Of course, my approach might be all wrong, so I'm open to new strategies on how to achieve this.

Thanks in advance for any help you can give me.

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 smouton123 · May 20, 2016 at 02:57 PM

Found my error. My editor-script's "OnSceneGUI" was using :

Handles.PositionHandle(component.MinPosition, Quaternion.identity);

instead of

Handles.PositionHandle(component.MinPosition, component.transform.rotation);

which explains why rotating the parent game object did not rotate my vertices.

I would still like to thank you @FortisVenaliter for your post!

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
avatar image
0

Answer by FortisVenaliter · May 19, 2016 at 05:42 PM

Well, if you use the local variables in the transform (localPosition, localRotation, localScale) that will only affect the object in relation to it's parent. So, if the parent dashboard is set to rotate with the camera, and you set your min/max in local coordinates, you can do it all in local space and the dashboard transform will handle the move to world space.

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 smouton123 · May 19, 2016 at 06:29 PM 0
Share

I will try this and let you know how it worked, thanks for the quick reply!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Play incorrect animations when is looking in other direction 0 Answers

Connecting transform with Vector3 4 Answers

How can i rotate this vector over time? 2 Answers

How do you perform multiple rotations on the same object? - (in a single frame) 0 Answers

Unity 2d object advanced rotation 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