ID:2538842
 
(See the best response by Lummox JR.)
Problem description: Need help adding a cone-directional light that changes direction with the players client movement (using Forum_Account's dynamic lighting library). I have tried for years but have never been able to do it. May someone please help me?

Please add me on pager or join my discord ( https://discord.gg/x32mvJf ) to help me add the more advanced functions that I have attempted for years but just can't seem to achieve. May someone please help me?



The deal with the library is that the directional light was only created for a lamp to be clicked on to change direction, but I want to attach it to a player and have it move and update direction with the player and I guess I am just not smart enough to figure it out on my own. May someone please help guide me to a solution so I can add it to my game?

Code:Default
    directional
dir = SOUTH

lum(atom/a)
if(light_dir(src, a) == dir)
return ..()
else
return 0


light_dir(atom/a, atom/b)
var/dx = b.x - a.x
var/dy = b.y - a.y

if(dy >= abs(dx))
return NORTH
if(dy <= -abs(dx))
return SOUTH
if(dx >= abs(dy))
return EAST
if(dx <= -abs(dy))
return WEST

return 0









Some of the extra junk I tried

Code:some of My bad Attempts
    Move()
..()
//if(light) light.loc = src.loc
if(light) light.dir = src.move_dir
light
directional
//move_dir

lum(atom/movable/a)
mobile=1
dir = move_dir
var/d = sqrt((__x + a.x) + (__x + a.x) + (__y + a.y) + (__y + a.y))
//center(d, a)
d = sqrt(d)
// if the turf is outside the radius the light doesn't illuminate it
if(d > radius) return dir
//if(d <= radius) return dir
if(light_dir(src, a) == move_dir)
center(d, a)
return ..()
//apply()

apply()
var/mob/m = owner

// only force an update of the entire view
// for light sources attached to players
if(istype(m) && m.client)
for(var/shading/s in range(m.client.view, m))

// if we haven't updated this tile's ambient light
// value, force an update
if(s.ambient != ambient)
s.lum(0)

return ..()
if(move_dir==null)
//src = /light/directional
//src.light.on=0
return
// else
//src.light.on=1
//return
//return SOUTH
if(move_dir==NORTH)
//src = /light/directional
dir=NORTH
return
//return NORTH
if(move_dir==SOUTH)
//src = /light/directional
dir=SOUTH
return
//return SOUTH
if(move_dir==EAST)
//src = /light/directional
dir=EAST
return
//return EAST
if(move_dir==WEST)
//src = /light/directional
dir=WEST
return
//return WEST
//dir = move_dir
//if(light_dir2(src, a) == move_dir)
//return ..()

//var/d = sqrt((__x - a.x) * (__x - a.x) + (__y - a.y) * (__y - a.y))
//locate(a)//light.dir = a.move_dir
/*if(istype(a,/atom/movable)) //if this is a movement between two turfs
var/dx = a.x - x //get the distance delta
var/dy = a.y - y
if(z==a.z&&abs(dx)<=1&&abs(dy)<=1) //if only moving one tile on the same plane, mark the current move as a slide and figure out the move_dir
move_dir = 0
//move_flags = MOVE_SLIDE
if(dx>0) move_dir |= EAST
else if(dx<0) move_dir |= WEST
if(dy>0) move_dir |= NORTH
else if(dy<0) move_dir |= SOUTH
//for(a)
if(dy>0)
//for(a)
light = new/light/directional(src,3)
dir = NORTH//stat("dir", "up")
//return cos(30 / d / radius) * intensity
if(dy<0)
light = new/light/directional(src,3)//for(a)
dir = SOUTH//stat("dir", "down")
//return cos(30 / d / radius) * intensity
if(dx>0)
light = new/light/directional(src,3)//for(a)
dir = EAST//stat("dir", "right")
//return cos(30 / d / radius) * intensity
if(dx<0)
light = new/light/directional(src,3)//for(a)
dir = WEST*/

//return cos(30 / d / radius) * intensity
//..()
//stat("dir", "left")
//stat("dir", dir)
//else
//return 0

mob/players/
proc
DIRL()
if(istype(M,/atom/movable)) //if this is a movement between two turfs
var/dx = M.x - x //get the distance delta
var/dy = M.y - y
if(z==M.z&&abs(dx)<=1&&abs(dy)<=1) //if only moving one tile on the same plane, mark the current move as a slide and figure out the move_dir
move_dir = 0
//move_flags = MOVE_SLIDE
if(dx>0) move_dir |= EAST
else if(dx<0) move_dir |= WEST
if(dy>0) move_dir |= NORTH
else if(dy<0) move_dir |= SOUTH
//for(a)
if(dy>0)
//for(a)
light = new/light/directional(src,3)
light.dir = NORTH//stat("dir", "up")
//return cos(30 / d / radius) * intensity
if(dy<0)
light = new/light/directional(src,3)//for(a)
light.dir = SOUTH//stat("dir", "down")
//return cos(30 / d / radius) * intensity
if(dx>0)
light = new/light/directional(src,3)//for(a)
light.dir = EAST//stat("dir", "right")
//return cos(30 / d / radius) * intensity
if(dx<0)
light = new/light/directional(src,3)//for(a)
light.dir = WEST
/*UDIR()
if(M.dir == NORTH)
//stat("dir", "up")
else if(M.dir == SOUTH)
//stat("dir", "down")
else if(M.dir == EAST)
//stat("dir", "right")
else if(M.dir == WEST)
//stat("dir", "left")
else
//stat("dir", dir)
*/


Please bare with me, I am originally a webscripter/designer/graphic developer so I'm sure my "wet noodles stuck to walls" code will make your eyes vomit. Please help me get better! I have no idea what to do half the time and no one guides me so I never learn more.

Problem description: Need help adding a cone-directional light that changes direction with the players client movement. I have tried for years but have never been able to do it. May someone please help me?

The closest I have gotten is generating a square of light around the player, or an incorrect light shape that doesn't properly change with the players direction. The cones I have generated go beyond the radius, don't follow the player and remain in a static position while a light source is attached to the player. Clearly I do not have a full grasp of what I am doing, let alone how to create a cone equation. Please help me so I can finally, after a decade of this burdening the project, add this to my game. Please. Anybody?! I'll reward you fairly if I must!


Please add me on pager or join my discord ( https://discord.gg/x32mvJf ) to help me add the more advanced functions that I have attempted for years but just can't seem to achieve. May someone please help me?

Best response
So as I understand it, you want a cone of light as a visual effect?

If so, bearing in mind that this won't take opacity into account (shadowcasting is a much harder problem), what you basically need is a decent-sized triangular icon and the right matrix transform.

Let's say you have a light cone icon that's 100x200, starting at the left edge and spreading out to the right, for a 90° spread. First, you'll need to transform it to get whatever target angle you want, and also to make sure it's centered.

#define TILE_WIDTH 32   // depends on your game
#define TILE_HEIGHT 32
// these tell us the size of the icon
#define LAMP_ICON_WIDTH 100
#define LAMP_ICON_HEIGHT 200
// these define how the cone will actually look
#define LAMP_CONE_LENGTH 160
#define LAMP_CONE_WIDTH 64

// Get a matrix that centers the origin of the light cone on the tile center
var/matrix/M = matrix(TILE_WIDTH/2, \
(TILE_HEIGHT-LAMP_ICON_HEIGHT)/2, \
MATRIX_TRANSLATE)

// Transform the icon to the right shape
M *= matrix(LAMP_CONE_LENGTH/LAMP_ICON_WIDTH, \
LAMP_CONE_WIDTH/LAMP_ICON_HEIGHT, \
MATRIX_SCALE)

// In this example, lamp is src and A is the target.
// Tile-based formula; does not take step offsets or bound centers into account
var/dx = A.x - x
var/dy = A.y - y
var/lamp_angle = arctan(dx, dy)

// Lamp_angle is defined as counter-clockwise from east.
// Since the icon points east, we'll need to rotate ccw.
M *= matrix(-lamp_angle, MATRIX_ROTATE)
transform = M


If this lamp were to animate its direction changes, you might want to take a different approach to limit the matrix to only the rotation step; e.g. use an icon that already has the right scale and use pixel_w/z to offset it.
I asked for an anthill and you gave me the moon and dunes of mars. Come on dude...

I love that you understand exactly how to make it do what you want and in a great way, but I can't use that with my existing code.

Thanks anyway...I'll try to use byonds new features in my next project, but it is just too much of a hassle to reprogram an entire decade+ old game source to use new functions.

I just want a simple classic byond way of making a simple directional light change directions with the user. It shouldn't be that hard...
I too wish to understand basic math problems, only I don't want to put in the effort to learn anything, so I'm hijacking this thread offering sticks of gum to someone who can make me an code that I can understand without reading or onboarding any new information.

Also, I need to be able to implement it into my game and make it do exactly what I want without including it in the source code or making any adjustments.

Kthx.
It isn't that I am unwilling to learn, it is that I don't quite know what to do. I can see how to do it but am not able to make it happen tangibly. It's fine, though, I don't mind just using circles of light. I wish I had a better grasp of it all, I wish I could ask FA for some help.

It is kind of like if someone hands you an automatic transmission and tells you to dismantle the entire thing. It would take a lot of trial and error and you probably wouldn't mind some pointers from someone who has done it along the way.

Directional lighting was merely designed into some of the aspects of the game due to being based on real life objects that mimic such effects. However, when I realized it would require every turf having to register every players direction, or something else, I decided against it. Circular lights will have to do. I also wanted to somehow combine the shadows properly but when utilized along side the items in my game (like a hand torch to create light on a user), it breaks the shading.

I've messed with the library several times and will continue to do so and maybe one day somehow get it to work but I feel I am missing a puzzle piece that I can't manifest out of thin air without understanding more from some guidance and God Bless whoever is willing to grant it to me.

As for the rest of you, God bless your stony hearts.


planes, MASTER_PLANE, vis_contents, appearance_flags, vis_flags, client, client.screen, mob

Read up on all those.

http://www.byond.com/developer/Kumorii/Kii_Spotlight
These forums should honestly just be removed. lol...

Welp, I tried.
The simple fact is, the way that library does it is obsolete and you're better off moving to something more suited for it. With plane-based lighting this would be as simple as giving your light a different icon with directional states.
With the default lighting engine, directional light is not possible in multiplayer. light-casting is range-based, and opacity cannot be controlled on a per-client basis.

What you are asking for is just not doable. So the people most knowledgeable about the engine have given you alternatives.

The way you came at Lummox's response was a massive slap in the face for taking the time to try to help you. He's too nice to say anything about it. I'm not.

Putting these absurd limitations on how the system you are asking other people to write for you is hurting you. It's stopping you from actually learning something.

Every single person in this thread learned DM incrementally over time, and can write just about any system you could dream up. If they all agree that what you are asking for is infeasible, that should be a really big sign that what you are asking for isn't going to magically appear. It's double not going to magically appear if you keep slapping at the people willing to help you like that.