Jump to content

coding lights


Recommended Posts

Some of this might be simple, some I know will be really complicated.

first of all, I made a mod that gives chester new morphs, one of which is supposed to glow. Sometimes he glows fine, other times he just doesn't glow. Any thoughts as to what might fix this?

and now the complicated one:

how could I code a flashlight, that creates a teardrop-shaped lightsource, from player to wherever the cursor is? basically just how would I code a flashlight?

I'm guessing the teardrop part is more complicated than the following the cursor part

Link to comment
Share on other sites

7 hours ago, mf99k said:

Some of this might be simple, some I know will be really complicated.

first of all, I made a mod that gives chester new morphs, one of which is supposed to glow. Sometimes he glows fine, other times he just doesn't glow. Any thoughts as to what might fix this?

You'd need to post what you have so we may see what you're doing and how to fix it.

7 hours ago, mf99k said:

how could I code a flashlight, that creates a teardrop-shaped lightsource, from player to wherever the cursor is? basically just how would I code a flashlight?

I'm guessing the teardrop part is more complicated than the following the cursor part

The teardrop would be an approximation since the lighting system are all point radial lights as far as I know.

Think of a line of circles with the circles expanding the further you go out.

This generates the teardrop in approximation.

 

Spoiler

rANqcid.png

Position, radius, intensity, falloff

1.000000000, 0.382683432, 0.9, 0.4
1.811256121, 0.693137709, 0.9, 0.5
3.280648734, 1.255449918, 0.9, 0.6
5.942095100, 2.273941348, 0.9, 0.6
10.76265612, 4.118690185, 0.9, 0.6

 

45 degree FoV using method 3 described below to calculate position and radius.

 

To calculate the light radii such that they form a perfect cone shape of FoV based on a position X, you can use the equation:

Radius = X*sin(FoV/2.0)

For testing, plot against Y = {1.0,-1.0}*tan(FoV/2.0)*X

Wi6F7qP.png

Further, for density alterations by picking the next value of X based off of the first value of X you have many options.

Three of them are listed here for your convenience.

1) Each next circle shall rest on the radius of the last

X = X + R

Spoiler

rGKmS7C.gif

2) Each next circle shall only touch the radius of the last

Let F = sin(FoV/2)

X = X*(1+F)/(1-F)

Spoiler

8iupO9S.gif

3) Each next circle shall try to minimize overlap and maximize area in the cone

Average #1 and #2.

X = ((X+R)+X*(1+F)/(1-F))/2

Spoiler

sMkk6OS.gif

 

Edited by CarlZalph
Added animated demonstrations of effects.
Link to comment
Share on other sites

9 hours ago, CarlZalph said:

You'd need to post what you have so we may see what you're doing and how to fix it.

The teardrop would be an approximation since the lighting system are all point radial lights as far as I know.

Think of a line of circles with the circles expanding the further you go out.

This generates the teardrop in approximation.

 

  Reveal hidden contents

rANqcid.png

Position, radius, intensity, falloff

1.000000000, 0.382683432, 0.9, 0.4
1.811256121, 0.693137709, 0.9, 0.5
3.280648734, 1.255449918, 0.9, 0.6
5.942095100, 2.273941348, 0.9, 0.6
10.76265612, 4.118690185, 0.9, 0.6

 

45 degree FoV using method 3 described below to calculate position and radius.

 

To calculate the light radii such that they form a perfect cone shape of FoV based on a position X, you can use the equation:

Radius = X*sin(FoV/2.0)

For testing, plot against Y = {1.0,-1.0}*tan(FoV/2.0)*X

Wi6F7qP.png

Further, for density alterations by picking the next value of X based off of the first value of X you have many options.

Three of them are listed here for your convenience.

1) Each next circle shall rest on the radius of the last

X = X + R

  Hide contents

rGKmS7C.gif

 

alright. I'm terrible at math but I can probably handle this.

can I see the code you used for the light prefab you took a screenshot of? like the full .lua file?

and how do I set up the player as the origin point and the cursor as the target point?

Link to comment
Share on other sites

37 minutes ago, mf99k said:

alright. I'm terrible at math but I can probably handle this.

can I see the code you used for the light prefab you took a screenshot of? like the full .lua file?

and how do I set up the player as the origin point and the cursor as the target point?

I'm just creating dummy prefabs and adding a light to each using a script in customcommands.lua for testing purposes.

scripts/prefabs/player_common.lua has a light put onto the player for lightning strike purposes.

 

F2J8FVD.png

More of a pointed flashlight feel.

30 FoV method 3.

Position, radius, intensity, falloff

1.0000000000000, 0.25881904510252, 0.9, 0.4
1.4786077087598, 0.38269183526244, 0.9, 0.4
2.1862807564039, 0.56585109769847, 0.9, 0.5
3.2326515799320, 0.83667179506715, 0.9, 0.6
4.7798235458220, 1.23710936588820, 0.9, 0.6
7.0674839413640, 1.82919944498120, 0.9, 0.6
10.450036237237, 2.70466840020840, 0.9, 0.6

 

As for making the item function with the player being the pivot and the cast out being the focal point, I'm not sure how you're going to tackle that.

My first thought was to parent the light stream to the player and poll the cursor position and RPC that to the server to get its position updated since mouse cursor position isn't sent to the server.

If you just want the flashlight to 'point forward' then it's a simple matter of just parenting the lights to the player and they'll keep their relative offsets.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...