# Creating LOS or flashlight shadow

#21

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

#22

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

#23

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

#24

The number of different coordinates possible?

Well if it were that it would be 768 x 1024

#25

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

#26

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

#27

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

#28

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.

#29

Sweet thanks! Will you post a link?

#30

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.

#31

That would be nice if you could do that

#32

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

#33

Ok sweet thanks

#34

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)

#35

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.

#36

How would one do the different angles?

#37

@CodeHelp
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?

#38

Now that looks like it will be hard to solve.

#39

Ya I’m stuck on that…

#40

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