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
1
Question by ZeFirestarter · May 14, 2015 at 11:42 AM · vector3.angle

Fade color depending on Angle (angle 360° instead of 180°)

Greetings people.

First of all, I want to warn you that I’m a noob and just starting out with Unity and scripting. So thank you in advance for taking time to read this.

I have different points of information on an object marked by World Space GUI buttons and dots (images).

Here is an explanatory photo.

alt text

I have an Orbit camera that rotates around the object and can zoom in and out.

What I want to achieve is that when I rotate towards the back of the object, the Button and dots on the back have a stronger color (alpha “color” is higher) while the two buttons in the front fade to 30% of their alpha “strength”.

I don’t want the zoom function to influence the fade, that’s why I thought it would be more convenient to work with Angle instead of Distance. But I only want to take into account the angle while I rotate in the Y-axis (from back to front ◄-►). I want to ignore the angle when I rotate Up-Down ▲-▼.

I used Vector3.Angle, but I can’t make it ignore the Up-Down rotation and my second problem is that with Vector3.Angle, the back and the front are both 90°. I need to differentiate back and front, so I would need a number from 0° to 360° or -180° to 180°.

I always calculate the Angle between the camera and the center where it is aiming at. I read in another answer that I should use Vector3.Dot, Vector3.Cross and Mathf.Sign. I tried to, but since I’m a noob the results weren’t as expected. I’ll be very thankful for any help or guidance in the right direction.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by WillNode · May 14, 2015 at 01:03 PM

unity's Vector3.Angle is always returning the nearest angle between two vectors, here's how I did to know the angle on clockwise direction (Y-Axis)

 float angle(Vector3 from, Vector3 to)
 {
   //Set 'to' vector so 'from' always Vector3.forward
   Quaternion q = Quaternion.FromToRotation(from, to);
   //Get rotation, the resulting value are between -180 to 180
   return angleY(q*Vector3.forward);
 }
 float angleY(Vector3 v)
 {
 if (v.z > 0)
     return Vector3.Angle (Vector3.forward, v);
 else
     return -Vector3.Angle (Vector3.forward, v);
 }
 

please note that to make this works, the Y value on both vector are always zero

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

Debug.Log(Vector3.Angle(ray.direction,hit.normal)); HELP! 1 Answer

Moving On Two Axes and Reading a Stable Angle 0 Answers

Forward angles 2 Answers

Get angle beetween surfaces 1 Answer

Hop from transform to transform in 2D game? 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