unitytips: ShadowCaster2DFromCollider Component

If you try to use a ShadowCaster2D in a SpriteShape the shadow produced will have a box form, no matter the form of your SpriteShape.

This happens because ShadowCaster2D does not update its internal shape according to the SpriteShape's form.

ShadowCaster2DFromCollider component

I created this script to help to have SpriteShape with ShadowCaster2D casting right shadows.
To use it you need to add a PolygonCollider2D or an EdgeCollider2D to your SpriteShape's gameobject and then add the ShadowCaster2DFromCollider component to the same gameobject.

Below you can see a video showing a scene with some SpriteShapes before and after applying the ShadowCaster2DFromCollider component.

Source code

This solution was based on this Unity Forum post: https://forum.unity.com/threads/can-2d-shadow-caster-use-current-sprite-silhouette.861256

Loading comments...
Tutorials

Articles

Labs