0
\$\begingroup\$

I'm working on a top-down 2d game in Unity. assume my world/map looks like this through the player's eyes:

img1

(The art isn't mine, this is just an example) Now by making art directly like this, I can control the "lighting" as in drawing lighter and darker areas in the grass to create the illusion of sunlight and shadow.

I like this since it's very convenient and lets me have a lot of control, however, How would I make the player sprite "react" to this "light"? for example, if the player sprite were to walk into the sunny/bright parts of the map then it should be lit up/ bright and if it walks into the shadow regions then it darkens up.

I'm okay with creating multiple sprites for this if necessary, however, how do I detect whether the player is in light or not? Is there a way to create some sort of mask or texture map that lets me change the sprite or add lighting somehow?

I'm sorry if this isn't a good question, I'm still new to unity.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

The Light2D component might help you. But note that it is only available in projects that use the Universal Render Pipeline (URP), not for the standard render pipeline or the high-definition render pipeline. (See the manual article on render pipelines for more information on which render pipeline to use for your project).

Note that with this package, you don't define shadows you define lights. The default state is in shadow, and you say what areas are lit and how they are lit.

When you install this package, you have the Light 2D component which has various options. Those that seem most relevant for your particular use-case are:

  • "Freeform light" which allow you to define a lit area using a polygonal shape
  • "Sprite light" which allows you to define a lit area by providing an image
\$\endgroup\$
1
  • \$\begingroup\$ thanks! this looks like it'll work! \$\endgroup\$ Feb 21, 2023 at 11:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .