Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

harleyrana

Shadows for moving Sprites

This topic is 5985 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi i need to get some realistic shadows for a 2D shooter. Should be easy enough, if i could figure it out! If there was a camera looking down, as the sprite moves right the shadow would follow it but more and more slowly as it moves towards the edge of the screen. Is that right? How would you scale the movement of the shadow following the sprite? Thanks heaps!

Share this post


Link to post
Share on other sites
Advertisement
A simple way to do it would be to scale your shadow in proportion to the distance between the sprite and the ''light,'' in the direction opposite the direction from the sprite to the light. For example, let''s say your light is at (0, 0) and your player is at (5, 0): You could scale your shadow 5 units to the right. When the sprite moves to (7, 0) you would change the scaling to 7 units to the right. You''d probably want to shrink the shadow down a little, though, for more realistic looking results. Changing how much you scale down by could simulate the light being at different heights!

Note that I haven''t checked the math for this, but I''m pretty sure that a linear scaling routine is not mathematically accurate (it seems more likely that some logarithm or maybe tangent function is involved), but from just speculating about it it seems like it would be a pretty good approximation, especially for sprites kind of far away from the light.

Hope this helps ~
~ riley

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!