How do i make a light get increasingly brighter when you look at it? (anamorphic lens flare, billboardgui)

Have you ever looked at a traffic light, and looked up and it got really blinding?
I want to recreate that.


This is the angles im using, 40 degrees. I want it so if the player steps in those angles, the light on the billboardgui increases in size and imagetransparency to 0, the deeper he goes to the middle of the light the stronger it gets.

Here is my part setup
image

Angleofattack is a Numbervalue set at 40, which controls the degrees

BaseSize is a numbervalue set at 12, which is the normal size of the lensflare, when player is not being blinded.

LF is a billboardgui, the lens flare.

Dont worrry about the random billboardgui.

This is really a free solve if yk what your doing.

4 Likes

Can someone really help me with this, i dont have much time!

There is a function for the camera that gives you the part’s position in the screen. I think you could use that.

1 Like

What’s the function? Is it something like worldtoscreen

Can’t you just do:

-lightdirection:Dot(cameraDirection) >= math.cos(math.rad(angle))

?

3 Likes

I’ll be trying this and ill update you!

1 Like

Lightdirection is the cframe lookvector right?
Aswell as the cameradirection too?

Yes, and the angle variable is in degrees, I ran a test and it seemed to work when I had 40 as the angle.

1 Like


image

Some weird stuff occurs.


The 40 degree angle becomes flipped. (green is right way, red is bad way)


(when it prints howepic, its basically saying it worked)

Put a minus in front of the Dot() product.

if - v.CFrame.LookVector:Dot(Camera.CFrame.LookVector) >= math.cos(math.rad(v.AngelOfAttack.Value)) then
1 Like

Ok! now its working, awesome, now i just need to add a way to detect if its within the part’s angle, and not the cameras angle. (angle follows the part, not the camera), you got any ideas to check if im within its boundries?

Can’t you just reverse the thing? By this I mean instead of:

partLookVector:Dot(cameraLookvector)

Just do:

cameraLookvector:Dot(partLookVector)

You’d just be checking if both of them are within their own angles. The first one would check if the player is looking at the light and the second one basically checks if the light is looking at the player.

Dunno, seems like the most intuitve solution but I might be missing something.

2 Likes

Did this, seems like the same issue is occuring, wherever you move, you can even be miles away from the part, it’ll still be thinking your in the lensflare spot, think you might’ve misunderstood.

The issue is uh, i need to detect if the camera is facing the part’s boundries, not your own.

1 Like

I just tried out what I told you earlier. Is this not what you are trying to achieve:

When the white frame is visible, that basically means there should be lense flare. Not sure if the video loaded, I never uploaded one before.
Edit: just found out I had to convert it to mp4

1 Like

uh. for me when i walk away from the part and keep looking at the direction i was looking, it keeps thinking thats the right way

You’re right I forgot about that!

1 Like

There’s a post that might be able to fix your problems, its a similar concept as yours.

Especially this section is very useful.

1 Like

I’m not exactly sure how to apply this…

1 Like

You would check if the player is looking at the light and also check if the camera is within the “FOV” of the light.

lookForward would be the LookVector of the light, lookToPoint would be the vector from the part to the camera (cameraposition - lightposition).Unit, and the FOV would be the AngleOfAttack, no?

1 Like

just realized how stupid i am. Theres a fricking / 2.
Hey while your typing, do you have any idea how to fade imagetransparency and size in, the deeper you get into the angle?!