• 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
2
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
Add comment · 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 : $$anonymous$$onoBehaviour {
     
     GameObject camera$$anonymous$$ain;
     
     
      float Brightness=4.0f;
     
     public float RelativeAngle;
     
     public float $$anonymous$$inHeadlightAngle=-170.0f;
     public float $$anonymous$$axHeadlightAngle=-30.0f;
     
     
     void Start () {
     camera$$anonymous$$ain= GameObject.FindWithTag("$$anonymous$$ainCamera");    
     }
     
     
     void Update () {
         
     // get positive or negative angle between cameraToHeadlight vector and headlight facing direction
     Vector3 Cam2Headlight = transform.position - camera$$anonymous$$ain.transform.position;
     Vector3 referenceForward = transform.forward;
     Vector3 referenceRight= Vector3.Cross(Vector3.up, referenceForward);
     Vector3 newDirection = Cam2Headlight;
     float angle = Vector3.Angle(newDirection, referenceForward);
     float sign = $$anonymous$$athf.Sign(Vector3.Dot(newDirection, referenceRight));
    
     RelativeAngle = sign * angle;
         
     // show/hide lens flare depending on camera's angle relative to headlight    
         CarCameras CarCameras = camera$$anonymous$$ain.GetComponent<CarCameras>();
         float distance= CarCameras.distance;
         LensFlare headlightFlare = transform.GetComponent<LensFlare>();
         
         
         if(RelativeAngle > $$anonymous$$inHeadlightAngle && RelativeAngle < $$anonymous$$axHeadlightAngle )
         {
             // 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, camera$$anonymous$$ain.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

· Add your reply
  • Sort: 
avatar image
1

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
Add comment · 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

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Lens flare not showing in game view. 1 Answer

Adding lens flare to sun 0 Answers

Car headlights effect 1 Answer

My Lens Flares Only Show In The Scene View? 0 Answers

emmit texture from shader 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges