Help with shadows

0 favourites
  • 9 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Hi guys, had a shadow working for my player character for a while but thought i'd now like to add shadows to all enemies. Getting stuck with this one! I can either make it so every enemy gets assigned a shadow - but they are not in the right places. As soon as the enemies start getting killed, instead of the shadow being destroyed by the nearest enemy, the shadow is changing position, then stacking (creating a big thick shadow on the last enemies). Or I can make the shadow appear in one spot (not where it should be) in one thick mass of all the instances of said shadow.

    The states are working fine - switching from idle animation to attack animation shadows but included the code to demonstrate what i'm trying to do. I'm sure I'm just missing something simple - maybe adding another instance variable of some description but after a good few hours I am officially stumped.

    Thanks guys!

  • Hi MrClifford

    Instead of creating the shadows using events, just make a container and include both the shadow and the enemy sprite. When the enemy is spawned the shadow will spawn to.

    You can use: Every Tick - Set shadow XY to enemy XY to keep it located (also angle if necessary), and assuming you have matched animations for the shadow and enemy, use: Every tick, set shadow animation.frame to enemy animation.frame.

    Then when the enemy is destroyed it will automatically be destroyed too.

  • Thanks calm - i'll check out the manual and see how they work as I havn't used them yet! Thanks a million

    Edit: Just read the manual and looks simple enough! I can change another one of my enemies now too to cut some events out! Thanks

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Unfortunately it doesn't work. The container works well and assigns each enemy a shadow - and destroys it too. Perfect. However, if i set the shadow to position to enemy XY then the shadow will move up and down with the enemy instead of fading on the floor with opacity.

    If on the first example I add in an every tick to the overlapping event it will occasionally add shadows to the upper enemies but they quickly disappear - then reappear.

    I found by altering the image point on the shadow sprite I could position it to the necessary position per enemy instance. This was to overcome setting the shadow to enemy XY. I found setting the position to enemy.X, ninjaShadowBar.Y was what was messing up the positions in the first place. Works fine for one instance, but not multiple!

  • Ok I think that should be easy to fix, just checking first. Are the shadows are supposed to remain on the ground and fade opacity out when the enemy is jumping, and you don't want the upper row enemies to have shadows?

    If that's the case I wouldn't recommend using the "is overlapping" condition to achieve what you are doing

    -Use a container like you have

    -Make an event to position shadows: Every Tick, set shadow.X to enemy.X. Set shadow.Y to floor-height

    -Make an event to control removing shadows for higher enemies: If enemy.y => maximum-height set shadow.opacity to 0

    -Make an event to control shadow opacity for jumping enemies: If enemy.y < maximum-height set shadow.opacity to 100-distance(enemy.x,enemy.y,shadow.x,shadow.y)

    I'll do a quick example to show you what I mean

  • Here you go. Works like a charm.

    https://1drv.ms/u/s!AkmrWgxeuxlKg_5vjCLQNeSnDs7ugA?e=4r3URh

  • Yes, that's what i'm trying to achieve, shadow remains on ground but opacity fades over distance. But I would like it for all enemies regardless of height.

    Your demo looks spot on but due to the fact i've been using an overlapping event to create shadows on for the player character, the levels are set a little differently. If I use your example, no shadows appear (i'm guessing due to various image points to set the distance without events). If I add in the overlapping loop to the enemies, shadows appear but do not change opacity. My brain is actually getting fried on this one!

    I've put an example of how a level is set up with the shadowbar (invisible) and how the ninja overlaps it. Works perfectly, but not for multiple enemies/heights.

  • I was just being a bit dopey! Got it all working now, just needed to set the shadow position to enemy.X,Self.Y and bingo! Thanks again calm, much appreciated. Just going to try and do the ninja shadow now in the same way - will mean levels wont take as long to make as i wont have to be putting that box along all the tilemap!

  • Good to hear.

    I've added a tutorial that covers this and also includes an option to scale the shadow as another effect. You can find it here: https://www.construct.net/en/tutorials/adaptive-platformer-shadows-2475

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)