Planet, moon and shadows!

Post your own tutorials, guides and demos.

Post » Tue Feb 03, 2009 10:20 am

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?
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Tue Feb 03, 2009 11:05 am

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.
B
5
S
2
G
4
Posts: 113
Reputation: 2,101

Post » Tue Feb 03, 2009 11:36 am

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...
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Tue Feb 03, 2009 1:38 pm

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).
B
5
S
2
G
4
Posts: 113
Reputation: 2,101

Post » Tue Feb 03, 2009 1:42 pm

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 :|
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Tue Feb 03, 2009 11:05 pm

This is neat, but I'm not sure if shadows add like that...
B
4
S
2
G
6
Posts: 161
Reputation: 2,597

Post » Wed Feb 04, 2009 8:21 am

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.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Wed Feb 04, 2009 2:12 pm

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.
B
5
S
2
G
4
Posts: 113
Reputation: 2,101

Post » Wed Feb 04, 2009 5:11 pm

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.
B
4
S
2
G
5
Posts: 641
Reputation: 3,011

Post » Wed Feb 04, 2009 7:36 pm

[quote="David":29m2f8bv]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.[/quote:29m2f8bv]

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



lol jk :mrgreen: , nice solution dav, had'nt thought of that.
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620

Next

Return to Your tutorials & example files

Who is online

Users browsing this forum: No registered users and 0 guests