(SOLVED) How to check if an object is in the light or not?

@MrMen This is genius, the only thing I don’t understand is the part where it says:
Cast the ray against “RayCastLightTest” >>> what is that? is it a group or what? and if it is what is inside it exactly?

Also if it’s possible to send me this test you made so I can study it better, I’d really appreciate it.
You can upload it on google drive for example and then put the link here or if you’d like you could just email it directly to me in a .zip file maybe: contactcoriandergames@gmail.com
Whatever works with you I’m ok with.

Thank you so much for helping out, I never thought this was possible, it opens a lot of possibilities.

Alright I’m just waiting for your input on this part that says:
Cast the ray against “RayCastLightTest”
I’d like to know what is “RayCastLightTest” so I can test the whole thing because without knowing what this is, the whole scene just crash when the preview starts?

I’ll be waiting for you…

Edit 1: Wait is the “RayCastLightTest” is that yellow object in your example?
I just attach it to the light? … I’ll be trying that now, I think that’s it

Edit 2: Nope still not working…

Edit 3: Alright that’s cool, I managed to get it to work, well kind of… I just made a group and I added the platform, player and light to that group and now it works but kinda…

There is a crash that happens when the light is very close to the player, the whole scene just crash and I’m not sure why, I’ll try using distance and see if that works…

Edit 4: Yup I confirm using distance fixed the crashing issue just fine, I also noticed that it’s working almost perfectly with multiple light sources and without using any “for each object event” which is epic because that means less calculations and better performance.

Now I said in Edit 4 “almost perfectly” and I’m super satisfied with the results but there is 1 instance where it doesn’t feel like very accurate, let me explain this:

This might be fixed using a blur filter for the light but I’m just nitpicking at the moment to get it to perfection (If we can for sure):

Here is the first case:
As you can see the light is intersecting the player and the color is not changed, it should be changed because it’s intersecting one of the points on the edges.

ray8

Here is the second case:
When the light angle is close to 90 degree, it’s perfect
I think once the light angle becomes bigger, it’s less perfect (Case 1) I’m not really sure…
ray9

If there is anything we can do about that, let me know about it…

But at this point, I’m super satisfied with the result
and I can’t thank you enough for such a genius idea : )

GOOD NEWS @MrMen and @Silver-Streak !!
I made it perfect using more point on the player, the more points, the more accurate it becomes.
It’s working so unbelievably perfect right now in all angles :smile:

MrMen Thank you so much for helping me with this complicated issue, your idea was fire honestly :fire:

And Silver-Streak thanks a ton for trying to think with me and help me with this :star2:

Thank you so much.

Now it’s time for me to test this idea and see if there are any issues with it, but for now I’ll edit the post as solved but I’ll keep testing and If I find an issue, I’ll update you here : )

1 Like

The raycast objects are the list of objects to test for a hit by a raycast. To me, if you’re raycasting from the light to the player (i.e. checking that the light is touching the player), then you want to remove the light source from this group. Otherwise it runs the risk of the raycast detecting the light and leaving it there.

And apologies, I did forget to mention that group :neutral_face:

And it’s good to read you have it working to your satisfaction. Good luck with the rest of the development.

1 Like

@MrMen Apparently I was wrong about 1 thing…
It’s not working with 2 light objects :pensive:
Only 1 light object is active even when using “For each light object”

Do you have any idea to make it work with 2 lights at the same time?

Here is what is going on at the moment while testing I found this:
This is the testing environment:

This is some notes added to it, so as you can see when light 2 is intersecting the object nothing is happening:

But when the object is intersected by light 1 it works just fine:

Light 2 is not active at all even when using for each on the whole event…

Let me know if you have an idea for that, I mean we can fix that by just using different light object and giving it the same event but that won’t be really optimized you know? I want it to be clean so if you have a solution for this to make it work with all the light objects at the same time just let me know and again thank you so much : )

I’ll be waiting if you got an idea for this…

I suspect you’re resetting the loop variable outside the For each light source. It should be within it :


This worked for me.

1 Like

@MrMen My goodness you’re a genius!
I totally forgot about the loop variable, totally didn’t do it like that! :sweat_smile:

It’s working perfectly now even with 3 light sources (Which is an overkill but I thought to give it a try for the ultimate test :joy:) and like it’s so detailed, it’s crazy good now!!

One thing I’m scared of though is how heavy this system is in the scene? I have 16 points on the character ray casting to different light sources all at the same time? is it that heavy? what do you think about this?

Yes, that’s one thing I’m not sure about. I suspect a few raycasts won’t hurt. But, you could test this by calculating FPS with raycasting and then without, and see if there’s a significant hit. Try it on a lower spec device for more dramatic results :smiley:

1 Like

@MrMen Yeah, well for now it’s at 60 fps stable so it’s all good, but I’ll soon test on my weaker laptop and see what will happen, I’m sure it will be fine but I’ll test it there just to make sure you know.

I’ll update here if I found any more issues about this…

That was a ton of fun to create this system, thanks a lot for helping out : )

1 Like

Take the FPS cap off and see how high it climbs. Then you’ll get a true indication of the performance impact

1 Like

oh i didn’t test that lol

My screen refresh rate is 60hz so that’s the maximum it can get for me :smile:

I wouldn’t have thought that would limit the FPS on the game though. I’ve had it where the FPS has gone through the roof (300+) on a device. I thought the monitor refresh rate limits to how often the monitor refreshes the image, not how many FPS the game manages to run at.

1 Like

@MrMen Hmm… maybe I’m using the wrong line of code then, I’m using this to show fps
ToString(round(1/TimeDelta()))

If there is another way let me know about it, I’ll try it for sure

Interestingly, I can’t get my FPS greater then 60. Maybe GDevelop caps it, and it was with Godot that I reached 3 figure refresh rates.

My usual method is to either count the number of frames drawn at 1 second intervals, or keep a running total of the number of frames and divide by the number of seconds that have passed since counting started.

1 Like

Electron is based on Chromium. Chromium hard forces Vsync, without a way to disable it. Your max FPS in a electron app will always be your monitors refresh rate. This includes GDevelop and any game made within it

2 Likes

Vsync yeah, I remember this now … that’s why you can’t get past your screen refresh rate.