• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED Simple Shadow Beneath Player

Telorr

Member
Hi!
I have a problem here.

I want to make simple shadow beneath the player. I want the shadow always stick to the ground (oBlock) whenever I move/jump. But, it only stick to the ground when I'm moving. When I'm jumping, the shadow will moved to the max room_height point. Please fix my code:
GML:
//DRAW Event
var shadowy = y + 96;
while (!place_meeting(x, y + 1, oBlock) && shadowy < room_height) {
    shadowy++;
};
draw_sprite(sShadow, 0, x, shadowy);
draw_self()
Help this newbie to solve his absurd problem. Thanks!
 

rytan451

Member
You're not changing the y coordinate within the place_meeting code. It's a simple mistake; I missed it the first four times I read the code. You should be using shadowy + 1 rather than y + 1.
 

jobjorgos

Member
I simply have this code to keep the shadow on the ground, even when jumping:
draw_sprite_ext(spr_shadow, image_index, x, y+2 - z_ground, 1, 1, image_angle, image_blend, shadow_alpha);

Just find a way to determine the z_ground. You can do it like this: if press space key, save players current y position as z_ground before jumping. You can also determine the jump height in z with this method.

And the shadow becomes even more dark/light depending on the jump height of the player:
GML:
if z == 0{shadow_alpha=1}else{
    pre_shadow_alpha = (z * 0.007);
    shadow_alpha = (1 - pre_shadow_alpha);
}
if shadow_alpha <0.5{
    shadow_alpha=0.5
}
 

Telorr

Member
Thanks for your answer guys! You gave me an overview of this problem.
Finally, I can solve it. Thanks!
 
Top