• 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
Question by Sondre-S · Jul 26, 2014 at 12:02 PM · careffectlens-flarelens

Lens Flare bug, sinks into colliders when moving

( Using Unity 3.5.7f6 )

I have two lense flares as headlights on my car. They work correctly at low speeds, but when exeeding a certain speed, the lense flare starts flickering and as the speed increases, disappers completely (because it's sinking into the collider behind it).

It looks like the brightness increases and decreases very fast and at the same time it fails to "keep up with the car" so it keeps sinking into the car collider behind it...

Edit: This is still bugging me, because the only way to get past this is to use the zoom value from the camera script to adjust the lens flare brightness, which doens't work for cameras that does't have a script attached and other objects thats far away from the camera.

I still think its really wierd that no one else has ever had this problem. Am I the only one who has tried to make headlights in Unity 3?

A car needs a collider, he headlights needs to be infront of that collider.... even calculating the distance from teh camera to the car results in this bug.

Comment
Stefan Alexander
Noxury

People who like this

2 Show 3
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 Sondre-S · Aug 25, 2014 at 02:56 PM 0
Share

Here's a script I have written as a workaround, its a bit of a hack and not really a good solution:

 using UnityEngine;
 using System.Collections;
 
 public class Headlights : MonoBehaviour {
     
     GameObject cameraMain;
     
     
      float Brightness=4.0f;
     
     public float RelativeAngle;
     
     public float MinHeadlightAngle=-170.0f;
     public float MaxHeadlightAngle=-30.0f;
     
     
     void Start () {
     cameraMain= GameObject.FindWithTag("MainCamera");    
     }
     
     
     void Update () {
         
     // get positive or negative angle between cameraToHeadlight vector and headlight facing direction
     Vector3 Cam2Headlight = transform.position - cameraMain.transform.position;
     Vector3 referenceForward = transform.forward;
     Vector3 referenceRight= Vector3.Cross(Vector3.up, referenceForward);
     Vector3 newDirection = Cam2Headlight;
     float angle = Vector3.Angle(newDirection, referenceForward);
     float sign = Mathf.Sign(Vector3.Dot(newDirection, referenceRight));
    
     RelativeAngle = sign * angle;
         
     // show/hide lens flare depending on camera's angle relative to headlight    
         CarCameras CarCameras = cameraMain.GetComponent<CarCameras>();
         float distance= CarCameras.distance;
         LensFlare headlightFlare = transform.GetComponent<LensFlare>();
         
         
         if(RelativeAngle > MinHeadlightAngle && RelativeAngle < MaxHeadlightAngle )
         {
             // if visible, adjust flare brightness depending on camera's distance to car
             headlightFlare.brightness= Brightness/distance;
           }
         // if not visible set brightness to 0
         else{headlightFlare.brightness=0;}
     
             
     }
 }
 

avatar image Sondre-S Sondre-S · Aug 05, 2015 at 05:11 PM 0
Share

I have found that calculating the distance to the camera

distance= Vector3.Distance(this.transform.position, cameraMain.transform.position);

also results in the same flickering/ disappearing...

Seems that setting the brightness based on any calculation, makes the flare disappear/flicker...

avatar image Sondre-S · Aug 06, 2015 at 07:39 PM 0
Share

Here's another solution. If I set up a bunch of box colliders around the flares, leaving a long tunnel behind them, the flares will stay on and act fairly normal, even at high speeds: alt text

riducoluscollidersetupforlensflares.png (356.8 kB)

1 Reply

  • Sort: 
avatar image

Answer by Stefan Alexander · Aug 21, 2014 at 08:35 PM

You need to make sure that the point lights (that is assuming that you are using point lights to generate your flares) are parented to the colliders in your car and have no physics components attached to them that may cause them to move back.

Comment
Sondre-S

People who like this

1 Show 9 · 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 Sondre-S · Aug 21, 2014 at 08:49 PM 0
Share

First, thanks for the reply:) Yes, that would seem like a plausible explanation, however I am not using point lights, just empty game objects with nothing but the lense flares, so they don't have any physics components attached either that could pull them back... It's very strange.

avatar image Stefan Alexander · Aug 21, 2014 at 08:54 PM 0
Share

Have you considered updating you version of Unity? It is very probable that if this is a minor bug, an update could correct this.

avatar image Stefan Alexander · Aug 21, 2014 at 08:56 PM 1
Share

I would also consider using point lights an then add flares to them. (If the reason you're not using the point light is because you don't want them to emit any light, you can just go ahead and drag down the intensity slider without affecting the flares).

avatar image Sondre-S · Aug 21, 2014 at 09:26 PM 0
Share

Thanks, yes, I have considered it, but installing a different version might mess up my project right? I upgraded my OS from Vista to 8 in january so decided to install Unity 4, but of course kept a backup of my projects. What happened was that most of the scenes were messed up, objects moved to different locations, scrips were full of errors due to obsolete stuff etc. I'll try to use pointlight as you suggested, I really hope that will fix it.

avatar image Sondre-S · Aug 21, 2014 at 09:46 PM 1
Share

I added a spot light and set it up correctly, and it works!! No glitching! Seems that the bug only occurs when the flare is alone and not used in a light component! Simple but effective solution, should have thought about it myself, but thanks a lot man! :) Edit: No, that doesnt work! :(

Show more comments

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

24 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

Related Questions

Adding lens flare to sun 0 Answers

emmit texture from shader 1 Answer

Car headlights effect 1 Answer

rotate the camera in the z axis 1 Answer

replacing Lens Flare for URP in version 2019 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