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 Alanimator · Mar 12, 2014 at 02:22 AM · c#lightingflare

How to changing Lense flare intensity based on its distance from the main camera

I have made a 3D space sim game ,I actually know how to get the whole changing of intensity of the lights done . but the calculations and procedures needed to successfully get a smooth fade of the lense flare is extremely bothersome.

so I have my space ship , a light component in the form of a point light is added to the space ships thruster spawn point at runtime , then a lense flare is added to each thruster spawn point.

 void Update ()
 {
 
 ControlThrusterFlareAndLightIntensity();
 }
 
 void ControlThrusterFlareAndLightIntensity()
 
 {
 
 try
 {
 Thruster.GetComponent<Light>().light.intensity = Vector3.Distance(Camera.main.transform.position,transform.position)/* + Calculation  that i need help with*/;
 }
 catch
 {
 return;
 }
 
 
 
 }

initially i had //Thruster.GetComponent().light.intensity = 5-(SpeedOfMyShip/10)

but the change in intensity was far too swift and because the flare never actually changes size the distance my ship moves from the camera became irrelevant . so the flare never got dim as the ship moved away from the camera .

It would be great if someone could help me out with that line of code so that this thing can get working :)

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

Answer by Pecek · Mar 12, 2014 at 03:08 AM

You can use Vector3.Distance() to get the distance between 2 points(in your case the ship and the camera), after that it's up to you how you want to use that value. I would lerp the intensity based on the distance(and probably clamp the distance so it can be in a certain range).

If you are not familiar with these functions, you can use something like this(it's not tested, sorry if there is any spelling errors)

 distance = Vector3.Distance(cam.transform.position, ship.transform.position)
 
 lightIntensity = Mathf.Lerp(0, 10, Mathf.Clamp(distance, 0, 1))

The above script is in boo, translate it to your language, and tweak the lerp/clamp values to get the desired effect.

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

21 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Making a light turn on and off with the same button 1 Answer

No shadows on directional and keep on getting this error 1 Answer

Image Effect lighting 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