Planet, moon and shadows!

This forum is currently in read-only mode.
  • This is just a simple demo of shadowcaster behavior in tandem with Light object. Move the light, watch the rotating planet and moon's shadows...

    Is there a way to detect whether an object is overlapped by the shadow?

  • As far as I know, there's no equivalent to an 'object is shadowed' event.

    You can use the Line of Sight object to *sort of* do this, but it detects Line of Sight to the hotspot instead of any edge that's in sight, so it's not exactly what you want.

    (Also, it doesn't work for your cap, I think because your hotspots are in odd places; they're being used for the rotation.)

    http://www.mediafire.com/?z2m43y9rdv7

    So you probably need to make something relatively inefficient, like shooting lots of sprites in the direction of the object you want detected (with a random component to make them spread out), destroying any that strike stuff that's in the way, and seeing if anything actually hits the target.

  • Or a condition that checks whether there is any of the objects (say, 'Celestial bodies' family) is between points A and B. That should be an efficient solution.

    Hmm, maybe draw an invisible line between Light and tested position, whenever it overlaps any of the objects, it would mark the position as 'shadowed'. I'm going to try that now.

    Edit: If only there was a "Rotate around position" action...

  • Yes, I could definitely use a 'rotate around position' action! But now that you've mentioned it, I'm pretty sure one of the math guys on the forum will quote a one-line expression involving sins, coses, and maybe lerps, and it'll somehow work perfectly.

    Anyway, here's a pretty good line-of-sight detector based on instant-hit bullets (which are effectively lines, because they just keep stepping in the same tick until they hit something). The light fires a stream of detectors at the moon that are interrupted if they hit the planet. See code comments for more detail.

    http://www.mediafire.com/?ra3xadhepzb

    Current accuracy looks pretty good to me, but might break down over long range. If you want better accuracy, reduce the size of the detector sprite, reduce the speed of the bullet behaviour, and increase the number of bullets produced per round. It causes slowdown if you scale it up a lot (eg, currently makes I think 40 bullets; 400 is too many).

  • That sounds like an idea!

    As for the math solution to orbiting, that would be too complex, because it'd have to take the parent object's movement into account (the velocity vector and such). Using maths would be like recreating the physics in Construct, where I just want the object to revolve around the parent object without messing with the hotspot

  • This is neat, but I'm not sure if shadows add like that...

  • Well, Construct shadows do add. I've been trying to find a workaround, but it'd end up setting the shadow to 'invisible' while passing over the shadow... I'd have to do pixel-perfect detection, which is simply too much hassle.

  • That is... troublesome. Difficult to avoid.

    I tried to make a counter-example, but failed - truly, impractically perfect detection is required. Absolute shadows would not add, but only due to maximum values already obtained. Realistic shadows incorporate ambient light, and usually cannot be represented by total darkness. No solution presents itself; an inbuilt event to the shadowcaster plugin is required.

    I find no solutions.

    So very drunk. Flatmate held large gathering, and for the first time in well nigh a year, I need not drive home. Apologies for unhelpful conclusion.

  • You could just put your shadows on a new layer, make the shadows 100% opacity, and then make the layer itself 20% opacity...that will give you semitransparent shadows.

  • You could just put your shadows on a new layer, make the shadows 100% opacity, and then make the layer itself 20% opacity...that will give you semitransparent shadows.

    and with that, David pwned the noobs. the end.

    <img src="http://i41.tinypic.com/wvqper.jpg">

    lol jk , nice solution dav, had'nt thought of that.

  • I don't understand... aren't shadows semi-transparents already? That is settable as Light property.

  • Hot damn, that's a good solution.

    Shadows are semitransparent already, yes. But it's at an object level, so if two shadows overlap, the effect adds. (Note: probably abusing terminology).

    David's saying that instead of making the shadows semitransparent, you can put the shadowcasters on a new layer and make the whole layer semitransparent.

    Because layer transparency is done at a whole-layer level, the shadows won't add to each other.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Oh.

    (A minute later)

    Oh!

    I feel so silly.

    100% opacity shadows add to 100% opacity when overlapping, so it is not quite visible, while layer opacity works uniformly. Brilliant.

    Edit: An updated cap has been attached.

  • That's looking good!

    I'd recommend moving the shadows layer below the objects layer, though - that way the shadows trail after the object instead of starting in the middle.

  • No, I intentionally moved shadows above objects - that way it gives the '3d ball' feel. Planets cast shadows that way

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