Hello! Can anybody help me with shadow under player? I'm creating 2D platformer and want create simple shadow, that stays on the ground and losing opacity and size when player jumps. Thank you!
You could child a SpriteRenderer to the player's character and position it so it's under the feet. This may require giving it a order-in-layer behind the player or changing its transform's z-value so that it renders behind the feet. Its sprite could be just a black oval. Then, have a ShadowController script. When jumping, have your jump controller (e.g. player movement script) communicate to the ShadowController the progress of the jump. As the jump goes up, the controller translates the jump progress to decrease the opacity of the SpriteRenderer and decreases the transform.scale of the SpriteRenderer's transform. "Jump progress" might be measured in relation to the height from the ground.
Basically, you raycast from the position of the character down (or direction of the light source). If it hits the ground or platform, then calculate the distance. Based on this distance, you can scale the shadow sprite and render it at the position that the raycast hits.