1
\$\begingroup\$

I've seen that the game "Alto's Odyssey" has a very nice way of projecting shadows on the ground the player is sliding on:

enter image description here

How could i replicate that? Would I use some shader magic, or by projecting a 3D mesh/image on the ground plane?

\$\endgroup\$
7
  • \$\begingroup\$ I don't know how the game looks while you are playing (how the shadow moves) but from the screenshot it looks like you just take the player's sprite, mirror it and scale it down on Y and place it on the ground. There is no point over complicating stuff with shaders and 3D meshes for a 2D shadow. \$\endgroup\$ Commented Oct 31, 2018 at 9:03
  • \$\begingroup\$ @TomTsagk the shadow squashes down when the player gets close to the ground, and gets stretched when he goes up \$\endgroup\$ Commented Oct 31, 2018 at 9:24
  • \$\begingroup\$ @TomTsagk that way though it wouldn't look believable... \$\endgroup\$ Commented Oct 31, 2018 at 9:25
  • 2
    \$\begingroup\$ @TomTsagk I'd upvote an answer about the technique you describe with a little more detail. \$\endgroup\$ Commented Oct 31, 2018 at 11:58
  • 1
    \$\begingroup\$ Wow, I had never noticed the shadow before... \$\endgroup\$ Commented Oct 31, 2018 at 12:37

1 Answer 1

1
\$\begingroup\$

My approach would be similar as mentioned in the comments. I would take a grey copy of the sprite and would have it mirrored. I would set an offset for the shadow which depends on how far the player is away from the floor. You can use Rays to check that. I also would apply the rotation of the player object to shadow object inversed (just the negative value). The shadow depends on how you set your imaginary light source. so you can use other values. But I would say.

float shadowOffset = playerheight / 2; //so shadow is always halfway-> for realistic light effects position = currentFloorPosition - new Vector2(0, shadowOffset); rotation = -playerRotation; //not sure about this line that it works shadowScale *= (shadowOffset * adjustValue) //maybe you need a adjust value which makes sure that the shadows size is good //code to find the actual postion of the floor 

so in this code example, you get a rough idea. You need to find the current position of the floor because it´s not constant as it´s curvy. You could also use the player position as a reference point for your shadow offset but I would be scared that the shadow jumps off the floor. To find the current position of the floor you could use a ray or a line cast and use the hit point as the current position. If you have any questions feel free to comment or message me. I hope I could help you. BTW these lines are more pseudo code than the real working code you might tweak some values etc.

\$\endgroup\$
1
  • \$\begingroup\$ I hope I thought right that shadows get bigger as you get farer away from your floor :P \$\endgroup\$ Commented Oct 31, 2018 at 20:06

You must log in to answer this question.