Creating LOS or flashlight shadow



Would there be a way to use math to figure out all the coordinates that are within the line of sight?


Well I mean you could split the figure up into triangles and that would make it easier


Ya that would work… You would have to figure out how to have triangular variables


The number of different coordinates possible?

Well if it were that it would be 768 x 1024


Kinda like the linear function of Y=MX+B, using that to see if something is within those coordinates


So it would be like seeing if the dot in this pic in the really shaded spot


Maybe If you’re trying to have the line of sight try this:
When Bear angle = triangle angle
Move forward
When bear x position = triangle x position
Check once if bear y position = triangle x position
(Pick up object set triangle invisibility percent 100)


Sorry for getting back to you late. I looked at the project, and it is possible to render the light very quickly. I got it down to 1 frame but in order to prevent lag it would probably be better to have it update once every 5-10 frames.


Sweet thanks! Will you post a link?


Thought i’d explain it instead. I’m not sure if I still have the project, and it was pretty sloppy coded. Tell me if you’d like to know how to do it yourself.


That would be nice if you could do that


Ok. I’ll do it tomorrow though, it’ll take a while to write the post.


Ok sweet thanks


There are a few techniques we need to use to make this as quick as possible.

  1. Clones. Create n amount of clones to draw n amount of ”light rays”.

  2. The fact that Hopscotch can execute several blocks in one frame.

  3. Collision detection. The build in bump rules are way to laggy for this kind of application. Instead, we’ll create our own.

What we will need to do each frame is: move the light ray and check for collisions.

There’s a special thing about Hopscotch where you can get stuff to execute much faster than normally: If you only put one block inside each rule, and put the rules in the same order as the blocks, it will execute in one frame.

Both these rules do the same thing, but ”Quick” does it in 1 frame
This means that we can do the (move, check collision) in one frame, without the lag from bump rules.
But if we code it in a certain way, we can actually (move, check) many times each frame. That way, we can do the whole light ray in one frame.

The way I did it was to move forward several times until hitting something. Then, drawing a trail back to the flashlight (due to a quirk with the Draw a trail blocks we need to use a special technique to Draw every frame)


Just fyi, the Move Forward block has a similar “quirk”. So in the Quick custom rule, it will only move forward every other frame.

Edit: I understand it may not matter if all the Move Forwards are in the same frame (using nested custom rules I assume), but thought I’d mention it all the same.


How would one do the different angles?


I got most of it but I’m lost at the block detection. It only works with the original block (the Tetris ones) but not the clones. Help?



Now that looks like it will be hard to solve.


Ya I’m stuck on that…


Looks great so far. What you’ll have to do is to have separate objects, since this method only works with the original object.