Need help creating a flashlight for my 2D top-down view game?

I am making a game involving some game mechanics from Project Zomboid. Such as the visibility mechanic in Project Zomboid. You can see a good few 100 feet in that game. However when inside a building, its cramped and often can only see one way. I drew examples below with a screenshot inside the examples.



The game that I am creating is a maze game. It is suppose to be pretty big. And then I need help with the thing where your mouse cursor controls where the camera goes while the camera still follows the player.

1 Like

You can use light source as your player
Then you have option to set what objects block light
Armed with that knowledge look at the picture below
And imagine you have 3 blocks around your player which are rotated with your player
And now you will stream light only like on picture below

So all you need to do is move these objects to your player and if player changes orientation you change orientation of these 3 objects also and you have your flashlight

1 Like

So what 2D effect should I add?

https://wiki.gdevelop.io/gdevelop5/objects/light/

1 Like

Hey, just wanted to say thanks! This really help. Oh and by the way, how do I get the light to follow mouse but only the light turns and doesn’t move from a specific object. Like if the player is moving and I want to shine the light to the back of my player, then I can move my mouse towards to the bottom of my screen and the light smoothly turns towards that direction.

How do I do that? I could stick it to the player but then when my player goes to turn, the stuff sticked to my player will not turn and just stay the way they are.

You are talking about like with top part of tank vs bottom part of tank
It had some name i just do not remember it

Anyway now you have 3 objects which you slap to player
How about you slap that 3 objects to another object called SpinPart
Now you attach SpinPart.Center to your Player.Center

And now you use action SpinPart rotate toward position MouseX() MouseY()

And your player can walk right and your can turn light all around your player into any direction while your player still walks right

1 Like