Help with Line of sight/lighting

Ok, so I’m working on my game, and I would like for the player to not be able to see the entire maze at once, or not be able to see through walls at all. Basically, to have the player only be able to see the things that are in the same hallway as them, only the things they would be able to see if they were genuinely in a hallway in real life. I’ve tried to do this multiple different ways (most of them involving raycasts) but all of them failed miserably, either causing so much lag the game became unplayable or just not working at all (some of them were a mixture of both). So I was wondering if any of you knew how I might accomplish this task. Maybe you know how to do this, @JR01? (If you look at the code of the player object inside of the Line of Sight bundle -->Rays bundle, you can see my most recent failed test attempt at just displaying the blocks to the right side.)

4 Likes

Make it dark and use lighting with a raycast that stops at first object.

2 Likes

have objects on the player that increase their X size until they hit something, I’ll send a screen shot in a sec

2 Likes

What do you mean by this? Like, what do you mean by “lighting”?

1 Like

Make it spawn light in front of you until the raycast length (of where it stops)

2 Likes

So, one of the things I already tried was getting the raycast length, and then moving from that spot backwards to the player, deleting the “darkness blocks” along the way. Is this what you are describing or am I missing something?

2 Likes

No. So make the player attach a light object, and set the x size of that object by sending a message. To figure out what size, use the raycast’s length.

3 Likes

So, how would this light object work? I’m sorry, I feel so dense right now. When you said “make it dark” earlier, how should I do that? Like my current system of spawning a black block on each grid square? And how would this light object growing allow the player to see what is going on underneath those black blocks?

2 Likes

Make everything 0 opacity, but the closer they are to the player’s attached light object, the higher the opacity.

3 Likes

Ohhhhh ok. That makes a lot more sense, thank you for explaining. I’ll try that!

2 Likes

So, I’ve been trying to do some testing with this idea, but it seems that I do not know how the attached object works, or the size object, for that matter. I created a nice little flashlight sprite for testing purposes, and I put a once into the “on” input of an attacher, attaching the flashlight to the player, but I don’t actually see it attached to the player. Then, when I put a number into the X input of the size block, it didn’t seem to do anything and I still couldn’t see the flashlight. Am I doing something wrong? Also, is the X input a percent increase or a pixel size increase? I’ve been treating it as a percent increase (using an equation to transform the distance into a percent increase).

Edit: nevermind, the flashlight object’s display order was too low. By increasing it I am now able to see it and see the stretch, but this led to another question, how would I attach an object at a different angle or a different side than it is currently at? Like, how would I get it to increase in size to the right instead of to the left?

Edit 2: Perhaps I should stop asking questions before trying different things, lol. I was able to figure it out by using a rotation block. Sorry for bothering you!

1 Like

It’s okay, glad I could help (FYI i didn’t even know if my idea would work, it just seemed like it would).

2 Likes

It definitely does seem like it should work, and I’ve finally managed to get the actual flashlight object thing behaving how I want it to, but for some reason, the proximity isn’t activating


I have code that fills the screen with “_BlackOut” objects and then the player’s code does a raycast for the nearest wall and sends the distance to the flashlight object through the light right message. All of the other code seems to function properly, and then the size block gets activated and the output goes into the check input on the proximity, but nothing is output even though the entire level is nothing but these “_BlackOut” objects. Why isn’t it detecting them?

Edit: I forgot to mention that changing the proximity’s search object from “_BlackOut” to something else DOES result in an output, so I am even more confused as to what is happening

1 Like

Do the “_BlackOut” object have collisions on?

1 Like

Ummm no, because if they did, then the raycasts would stop before reaching a wall, which would be an issue, because they are set to stop at first object so that they don’t go past the nearest wall (because I think that’s how raycast works, maybe?)

1 Like

objects can’t be detected with proximity if they have collisions off

1 Like

Well, that definitely makes a lot of sense, then, lol. Could you tell me how raycasts work? If I turn off stop at first object, will it still just output the first instance of the wall that it intersects? Or will it output multiple times if it intersects multiple wall objects?

1 Like

It outputs the first object that is selected for it to detect. (It will only output once)

1 Like

Oh, yay that’s amazing! That makes everything so much easier, lol. I’ve been making things more difficult than they needed to be. Thank you!

1 Like

I felt like I should go ahead and update this thread on my eventual solution to the issue (in case people with the same issue find this later). I ended up making a new thread asking for advice

Basically, the final solution was to shoot out a projectile every time the player moved that caused the darkness blocks to go invisible when they were within a small proximity of the projectile and then have the projectile get deleted upon hitting a wall. This solution, however, does not provide for the blocks becoming dark again, as I decided that this would not be necessary for my game.

Thank you to Galactian and CodeAlpaca for all of your assistance on this post!

2 Likes