ShadowCast + Raycast Bug in my Vampire Game

Not favoritedFavorited Favorited 0 favourites
  • 2 posts
From the Asset Store
HTML5 Game Bundle (7 Games) – Created with Construct 3
  • Hey all,

    Working on a stealth game where you play as a vampire avoiding the sun. You can move the shadows by moving the lightsource.

    I use the shadowcast behavior to show shadows visually, but I have a function that handles if the player is overlapping the shadow (since you can't check that collision).

    The function works great except for a recent development causing issues. I've tried rewriting the function a few times but no dice. Would love some feedback on how I can make this work better.

    It's a weird system, so I'll attach the function screenshot, explain how it's used and then a picture i drew explaining it.

    This is the function. It takes a pointX and Y and returns whether that point is in shadow (0 is not in shadow, 1 is in shadow)

    I call the function on all ticks on 4 image points of the player. If all 4 image points return false, I assume the player is exposed to the sun and deal damage.

    Here's a drawing showing the problem.

    The system works great normally. But I've started adding other obstacles that are solid objects which are interfering with the raycasts.

    The weird thing is that I've had fences (solid, 9-patch) and they don't cause the same issue. Not sure why that is.

    Here's a gif showing the problem in action.

    media3.giphy.com/media/v1.Y2lkPTc5MGI3NjExOGM4emh1cTY3bzY0MW93eHY1cDQwN3dkZ3Y1cTlvdGFkaDR5a3NtMCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/X6K1SqO0z2kBSHHkoM/giphy.gif

    Any help or ideas would be much appreciated. Seems like a simple problem but for some reason I'm stumped. If only I could just only consider raycast collisions on shadowCaster objects.

    Thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I found a solution: use DrawinCanvas and pixelColor with sprite collision polygon points. I created the project for you.

    This requires:

    DrawinCanvas(getPixelColor),

    Second ShadowLight for collision (pixel color),

    Second player sprite for collision (uses polygon collision points)

    in runtime:

    You can drag&drop light source, move player with arrow key, scroll in layout (work with canvas)

    in editor:

    edit polygon collision, modify shadowHeight individualy (from shadow caster)

    resolution of canvas (not affect detection)

    Youtube (video):

    youtube.com/watch

    Project File:

    drive.google.com/file/d/1kmcNZvUHXezepH6J5YOd325XL5nz10t2/view

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