Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Player bottom shadow

Discussion in '2D' started by Generic_Username_12345, Apr 2, 2020.

  1. Generic_Username_12345

    Generic_Username_12345

    Joined:
    Jul 18, 2017
    Posts:
    3
    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!
     
  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
    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.
     
    eses likes this.
  3. cybergamedeveloper

    cybergamedeveloper

    Joined:
    Aug 10, 2020
    Posts:
    5
    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.