Creating LOS or flashlight shadow



Welp, here we go. I am trying to make a code challenge where you code a character go and take something and I need help with the line of sight part so when the character’s line of sight hits an object, if distorts accurately.
Kinda like this…

Here is the test project(it has as joystick so it is easy to test angles and stuff)

(@Hopscotcher helped me with the joystick and turns)
It is supposed to be a top down strategy style game (kinda like LoZ(legend of Zelda)


@FearlessPhoenix what did you edit?


I’ll see what I can do to do the flashlight effect


Like you wanna make that in Hopscotch?


So you want the light from the flashlight to stop at objects? That’s a bit of a challenge.
It’s possible, but i’d need more info about your game (i.e does the character move on the screen? is the floor a single color?) to be able to help.


Yes on all your questions… thanks for the help!


I made this project. It works, just takes forever.

@CreationsOfaNoob is there a way to make this faster?


I’m not COAN, but I’m pretty sure that you can make that faster somehow. I don’t know how though.


Ya that’s the only problem I have right now with it


This is going to get quite advanced, so just tell me if I should explain anything further.

  1. Use clones to draw all the light rays simultaneously. This one is pretty self-explanatory.
  2. Increase the speed that the lines are drawn with. Basically, the rays move a bigger distance every frame.
  3. Change the collision detection. You are currently using the default When Bumps rule, which makes the project lag quite a bit. Instead, you can check if “abs((obstacle x) - (light ray x)) < (obstacle width)” and the same for y/height. This saves a lot of lag and can be more exact.

These are some easy ways we can make it quicker, but if you want it to redraw every frame we’ll have to go a step further.


@CreationsOfaNoob I tried the clones, but how do you rotate just one of them?


I neither am COAN but you can use the clone index rule:

When ((self) clone index = 2)
[/set angle (95)]



When I do that, it does all of them… How does it work on the cloning part?


You can do “when object is cloned: set angle (clone index)”
If you want the clones to be more spaced out, multiply clone index by something.


Ahh that makes sense! Thanks for getting back to me! I’ll try that @CreationsOfaNoob


@CreationsOfaNoob can you help me with the clones part? I can’t figure it out


If you post a link to the project, I can take a look at it.


Here is the link

If you want me to walk through the code I can @CreationsOfaNoob


You should use a Create Clone times n from my Secret Blocks (copyable) to render light quickly


I’ll check it out! Will you post a link?