Detect Shadow Collision

0 favourites
  • 10 posts
From the Asset Store
professionally animations with Brashmonkey Spriter !
  • I'm working on a top-down game within a similar vein as the original Metal Gear game.

    There will be objects and enemies that have light sources and thus incite objects to cast shadows. My spy character will use these shadows to hide from immediate detection via line-of-sight.

    As enemies move about with their light sources, the shadows, of course, will adjust and what was once darkened by shadow will be cast in light.

    What I want to find out is if it is possible to test if a character - namely, my main character - is overlapping/colliding with a shadow as it is cast from an object with the shadow cast behavior.

  • If I understand you correctly and my brain actually works, you don't need Shadow Collision if you have Line of Sight and the shadows move with the enemies.

    Since the calculation of line of sight and shadows work almost the same (covering the area between the lines that go from the enemy to an object's left and right edge), line of sight will have the same triggers as a shadow collision.

    Of course, this only applies if your movable light sources are all attached to enemies.

    It is different, if there are moving light sources that aren't attached to enemies.

    But in your description, it sounds like the first case.

  • Sorry for the confusion. Not all light sources will be attached to enemies. Some will be static cameras or enemies who have no light affixed to them. Some light sources will be stationary, too.

    Basically, what I am looking for is how to detect when my character is in a shadow area as cast by an object with the shadow caster behavior.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Still, what randomly said is right. You just have to turn around the logic.

    Use line of sight on an object that sits on the light sources. When it see's an enemy (whit the shadow casting objects as obstacles) set a boolean in that enemy.

    Has LOS to object picks that object.

  • I'm not sure I follow...

    Whether or not enemies are around or not, ultimately I just need to detect if a character is in the shadow cast by an object.

  • That's what they tried to explain. For every light source you have. Also use a line of sight behavior on that object. If your character is in the shaddow, that means he is also not in the line of sight, looking from any light source.

  • OOOOOOH!!! ... I get it now.

    I thought they were getting confused about my mentioning how some enemies will have their own light source.

    Apparently, I'm (also?) the one confused.

    However, one problem remains, I plan to have the shadows defined by the height property of the shadow/light. So the shadows will not extend forever into the distance. That's why I need a way to test if the character is literally in the shadow that is cast.

  • LOS has a range.

  • You'd either have to modify the behavior so you can get at the shadow shapes or you'd have to calculate the shadow shapes with events the same way the behavior does it. To do the latter you'll need to be able to access the points of a collision polygon, but since you can't access that with events you'll either need to make a plugin to access the points or add a bunch of imagepoints in the same places. After that you could use some math to see is the player's location is inside those polygon shapes.

  • Adding to R0J0hound :

    The only (unlikely, but maybe applicable) exception to the disability to access collision polygon points would be if your obstacles (i.e. Shadow Casters) are rectangular and not rotated.

    You would now be able to get the X and Y of a collision polygon point by combining the object expressions BBoxLeft, BBoxRight and so on.

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