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 BHS · Feb 02, 2012 at 01:05 AM · rotationvector3texturesfade

Slowly fade texture only when when looking up?

Hi,

This seems like it shouldn't be too hard but I'm kind of stuck.

I'm not too familiar with Vectors so I'm a little confused. I'm using the angry bot's texture fade script and I'm trying to modify it. I got it to fade when the player looks up, but it also fades when the player spins around at certain rotation angles. How can I make it so it only fades when looking up?

Here's the code:

#pragma strict

var cameraTransform : Transform; var glowColor : Color = Color.grey; private var dot : float = 0.5f;

function Start () { if (!cameraTransform) cameraTransform = Camera.main.transform; }

function Update () { dot = 1.5f * Mathf.Clamp01 (Vector3.Dot (cameraTransform.forward, transform.up) - 0.25f); }

function OnWillRenderObject () {
renderer.sharedMaterial.SetColor ("_TintColor", glowColor * dot);
}

Or this? Sorry for the weird format, I use the code paste but it doesn't work..

#pragma strict

var target : Transform;

var mistColor : Color = Color.grey;

private var angle: float = 0.5f;

 var targetDir = target.position - transform.position;

 var forward = transform.forward;



function Start () {

 if (!target)

     target = Camera.main.transform;

}

function Update () {

 angle = Vector3.Angle(targetDir, -transform.up) - 0.25f;

 

  if (angle < 90.0)

 renderer.sharedMaterial.SetColor ("_TintColor",  mistColor * angle);

 }

}

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

Answer by aldonaletto · Feb 02, 2012 at 03:37 AM

The dot product between two unitary vectors result in the cosine of the angle between both. This means that the dot product will return a number between 1 (when the camera is parallel to the other vector) and -1 (when pointing to the opposite direction). In the first script, you could just use Vector3.up as the second vector, like this:

...
function Update () {
    dot = 1.5f * Mathf.Clamp01(Vector3.Dot(cameraTransform.forward, Vector3.up)-0.25f);
}
...
Using transform.up like in the original code could give strange results if the object was not in the upright position.
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 BHS · Feb 02, 2012 at 04:39 AM 0
Share

Thank you so much, I get it, but it fades when I look down, I want it to fade when I look up. I tried Vector3.down and -Vector.up but neither worked..Any way to fix this?

Edit: Never $$anonymous$$d got it I just used cameraTransform.up ins$$anonymous$$d of cameraTransform.forward.

Thanks again, you've earned this.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Transform a Vector by a Quaternion 1 Answer

Rotate One Object Around Another 1 Answer

slowly rotate a object *need quick fix* 0 Answers

Lookat function moves object backwards 0 Answers

Relative 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