Creating LOS or flashlight shadow

code
‮edoc
code⁣

#1

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


#2

@FearlessPhoenix what did you edit?


#3

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


#4

Like you wanna make that in Hopscotch?


#5

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.


#6

Yes on all your questions… thanks for the help!


#7

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


@CreationsOfaNoob is there a way to make this faster?


#8

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


#9

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


#10

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.


#11

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


#12

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

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

@Mindcool24


#13

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


#14

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.


#15

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


#16

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


#17

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


#18

Here is the link


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


#19

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


#20

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