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)
Tags:
@pomtl
@CodeHelp

11 Likes

@FearlessPhoenix what did you edit?

2 Likes

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

3 Likes

Like you wanna make that in Hopscotch?

3 Likes

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.

3 Likes

Yes on all your questions… thanks for the help!

1 Like

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


@CreationsOfaNoob is there a way to make this faster?

4 Likes

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

2 Likes

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

2 Likes

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.

4 Likes

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

2 Likes

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

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

@Mindcool24

1 Like

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

3 Likes

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.

2 Likes

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

3 Likes

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

2 Likes

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

2 Likes

Here is the link


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

3 Likes

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

2 Likes

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

1 Like