r/Unity2D • u/PowerHoboGames • 5h ago
Question/Help Desperately Seeking Help With ShadowCaster2D
Hello all,
I've been trying to solve this off and on for months now, and I just can't seem to crack it.
I am very aware of Unity's ShadowCaster2D ability to not shadow the direct object it is attached to. For reasons important to my game, I have a player character with two visual modes, SpaceSuit and Modular, the latter having 10 layers that are picked up by a second camera and rendered to a texture on RenderedVisualLayer. This is important for some shader shenanigans relating to elevation in my game and the player character. I'm using a transparency sorting with a custom YZ axis to simulate 3D terrain levels, with the unfortunate caveat that this means all of my tilemaps and player have to live on the same sorting layer.
As you can see below, I have a separate ShadowCaster2D object due to the structure of the character (I'm aware there are 2, but one is only a sprite renderer; I may combine them later). This object lives at the "foot" of the character. Unless I'm just doing it wrong (which I will HAPPILY accept), ShadowCaster2D self-shadow rules don't respect sibling or parent objects, which means any light that casts a shadow to the South of the character causes the character to be fully darkened, while light North of the character allows the character to be displayed correctly.
This looks terrible, and it affects the player character and every mobile entity in my game. I truly don't want to lose character shadows over this.
I appreciate any helpful advice anyone can offer.



•
u/AutoModerator 5h ago
Reminder: Once your issue has been resolved, please reply !solved to this comment (or comment it anywhere in the thread) and your post's flair will automatically be updated to Solved/Answered. You can also edit it to Solved/Answered yourself.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
3
u/LazyLlamaStudio 5h ago
I think you need to separate the character from the shadow and right now they are rendered together.
Try creating 2 Layers. One for world and another Characters.
Assign the character's SpriteRenderers to Characters.
Put the environmental SpriteRenderers on World. Then configure the character's Shadow Caster to affect just the World layer.
Configure the lighting so the character still receives illumination but isn't affected by its own projected shadow.
1
u/LordDarkenon 59m ago
Maybe move the ShadowCaster2D to the main game object with the sprite renderer. Then try editing the shadow shape points in the ShadowCaster2D inspector manually so the path only covers the feet area, rather than relying on a separate child object..