Limited player vision with lights
2020/09/23
- Type
- Learning Resource
- Format
- Tutorial
- Version
- Godot 3.x
- Code
- MIT
- Game Assets
- CC BY-NC-SA
- All else
- 2016-2026, GDQuest© - All rights reserved
- Created
- Updated
- 2020/09/23
- 2020/09/23
In this tutorial, you will learn how to make a player with limited vision using Light2D nodes.
The limited vision mechanic consists of:
You can download the full project of this tutorial here.
We are going to use two Light2D nodes to implement this effect. One will add light and shadows to the environment, while the other will occlude the lit area's enemies.
For the first light, add a texture and enable shadows by checking Shadows->Enabled. You can find a soft circle texture to use for your light in the project linked above. Set the Mode attribute to Add. Doing so adds the light's value to underlying pixels.
We can use the light's cull mask to control which nodes it affects. Update the Range->Item Cull Mask property of the light so it only has Layer 1 enabled. That's the first rectangle in the top-left of the grid.

By default, all sprites are on the light layer 1. You can change that by selecting any node that extends Node2D, including sprites and tilemaps, and changing their Visibility->Light Mask property.
For the second light, use the same texture, enable shadows, and change its Mode to Mask. The mask mode hides sprites outside the light's area.
Set its Range->Item Cull Mask to Layer 2. With this, the light only applies the mask to nodes with Layer 2 enabled in their Visibility->Light Mask.

All nodes you want the mask to occlude should have Layer 2 layer enabled in Visibility->Light Mask.
In the demo project, the Player and TileMap nodes have only Layer 1 enabled in Visibility->Light Mask.

Enemies have both Layer 1 and Layer 2. As a result, the masking light will only occlude enemies.

Don't stop here. Step-by-step tutorials are fun but they only take you so far.
Try one of our proven study programs to become an independent Gamedev truly capable of realizing the games you’ve always wanted to make.
Get help from peers and pros on GDQuest's Discord server!
20,000 membersJoin ServerThere are multiple ways you can join our effort to create free and open source gamedev resources that are accessible to everyone!
Sponsor this library by learning gamedev with us onGDSchool
Learn MoreImprove and build on assets or suggest edits onGithub
Contributeshare this page and talk about GDQUest onRedditYoutubeTwitter…
Site in BETA!found a bug?