How do I cast a shadow on the highest platform below my character?

0 favourites
  • 5 posts
From the Asset Store
A pack of 76 platform designs for a platformer game with a mushroom/jungle theme
  • I'm making a platformer with multiple lanes by using Colludium's Platform2 Behavior. This makes collision events a little different.

    When the player jumps or is thrown into the air they need to create a shadow sprite that follows their X position and is destroyed when they land. That stuff is all easy to setup, no real concerns there.

    Where things get difficult is adjusting the Y position of the shadow sprite object based on the highest Y position of any solid object underneath the player.

    Additionally, the Platform2 behavior utilizes collision masking, meaning there are multiple layers of platforms in my game so we also want to ignore the layers not currently in the same "ZLane" as the character casting the shadow.

    Ideally this solution also can account for dozens of these shadows being cast at a time, as I would like the non-player characters to cast them as well (so long as they are on screen of course).

    I've tried a couple approaches to this but nothing has worked to my satisfaction thus far. I really do want shadows in because it helps the player know what lane theyre in and where they can expect to land.

  • Just as an update, I have been able to figure out half the issue by utilizing a suggestion left in this thread:

    construct.net/en/forum/construct-2/how-do-i-18/blob-shadows-69294

    My code now uses a "While" loop that checks to see if the shadow is overlapping a platform, and if that platform is in the same "Z-Lane" as the shadow. If it is, it sets the shadows Y position to shadow.y-1

    This now means that the shadow snaps to the top of a platform IF the player jumps from a low point to a higher point. However I cannot come up with a solution that doesn't create an infinite loop to snap the shadow downwards.

    Any suggestions?

  • The easiest way to avoid infinite loop is to include a condition like "loopindex<100" to the While loop.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The easiest way to avoid infinite loop is to include a condition like "loopindex<100" to the While loop.

    While that's useful to know it doesn't actually help in this situation. The problem is that I can't come up with a way for this While loop to have something resembling an "else" that doesn't create an infinite loop.

    Currently I have a "While" loop that checks to see if the shadow is overlapping a platform, and if that platform is in the same "Z-Lane" as the shadow. If it is, it sets the shadows Y position to shadow.y-1

    This causes the shadow snap to the tops of platforms higher than its starting position, but I cannot figure out how to reverse this and have it snap to the tops of platforms lower than it's starting position.

    Pseudocode wise it needs to look something like this:

    While

    NOT Overlapping a platform

    OR

    Overlapping platform, but platform's Zlane is not equal to shadow Zlane

    Set shadow.y to shadow.y+1

    But if I just do that, it will flip between the previous while loop and this one.

  • It would be easier to help if you could post a demo capx (preferably without any third-party plugins).

    If you need to use OR-condition with While, you can do this with a boolean variable. Something like this:

    variable b=1
    
    While (b=1 AND loopindex<1000)
    
    		: set b=0
    
    
    	NOT Overlapping a platform 
    		: set b=1
    
    
    	Overlapping platform
    	AND platform's Zlane is not equal to shadow Zlane
    		: set b=1
    
    
    	if b=1 
    		: Set shadow.y to shadow.y+1 
    
    
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)