How to cast shadows

Get help using Construct 2

Post » Sat Dec 21, 2013 8:00 am

Dear community,

I'm not sure if this is the done thing... May I humbly present my Shadow Casting Tutorial link. I hope you enjoy it and that you might find it useful.

Ed
I only occasionally visit - I'm learning C# for Unity, but c2 is still a respectable game engine imo....
B
73
S
19
G
66
Posts: 2,198
Reputation: 42,188

Post » Sat Dec 21, 2013 3:27 pm

Great!
B
43
S
6
Posts: 79
Reputation: 4,235

Post » Sat Dec 21, 2013 9:24 pm

hahahahahaha, what the hell ,

Don't get angry I am laughing on myself, because you know what , when I read you topic "How to cast shadows" I was thinking to reply that for now it's not supported fully in C2 and we have to like make it fake or something like that. But when I get into that link of yours, I was like WOW and got shocked, and then I start laughing on myself , hahahaha.

Thanks for sharing and making such a great tutorial.
B
94
S
19
G
15
Posts: 198
Reputation: 14,421

Post » Sat Dec 21, 2013 9:40 pm

Thank you very much for the kind comments! I got a bit bored this morning (jet lag playing havoc) and I needed a break from tinkering with one of my projects.
I only occasionally visit - I'm learning C# for Unity, but c2 is still a respectable game engine imo....
B
73
S
19
G
66
Posts: 2,198
Reputation: 42,188

Post » Sat Dec 21, 2013 10:30 pm

Shadows add on top of each other, should fix that.
Still not a bad idea, even though objects are not affected by shadows. If your object doesn't have a C(infinity) rotational axis along their vertical middle axis, shadows will be deformed. Simple shadows should be doable without problems though, as you show.
In the end I think if someone wants dynamic lightning, they should just stick with a 3D solution.mindfaQ2013-12-21 22:33:41
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Sun Dec 22, 2013 1:20 am

Yeah, of course shadows with < 100 opacity will always add to each other if they overlap. I can't think of an easy way to improve on the current simple demo/tutorial without creating other problems or failings (with my limited skills, of course). Is there an easy fix you can think of or that you are hinting at when you say "should fix that" @mindfaQ - any suggestions would be appreciated?

Before writing the tutorial I had a good look at Pode's 2D Dynamic Lighting: but it doesn't produce shadows as far as I understand (and I'm happy to be corrected) and it requires the use of a 3rd party plugin (unsupported by Scirra in the event of an update causing a crash) and it requires the use of additional software that, as a hobbyist, I'm not familiar with nor inclined to learn how to use (Im still learning how to use C2 when Im not distracted by my day job).

Thinking as I type - I suppose if the ground had a uniform fill colour with no texture effect then each shadow could be made from a darker shade of the ground's colour. Then shadow overlaps would not affect each other. However, that solution would obliterate any ground texture and, therefore, would be a viable alternative but with a huge trade off. Also, in situations with diffuse lighting in the real world, shadows can overlap and 'add' together - they are rarely exactly the same shape as the casting object unless you are very low to the ground... The same applies to situations with multiple light sources.

When you mention that this only strictly applies to objects with a rotational symmetry about the z axis - I agree, the tutorial only demonstrates shadows cast by such objects. If you want to create complex shadow casting objects then I cant think of an easy way to do it in C2, the only (and long) way I can think of would be to create a LOT of differently shaped shadow sprites and then select the appropriate one according to sun position and object angle. However, although I havent tried it, I imagine that youd be on a hiding to nothing because it would be very hard to implement and still wouldnt be as good as anything Unity could produce.

I agree with your last comment: if you want a realistic 3D shading solution for your game, dont use C2! But weve got to struggle on with the tools available...     
I only occasionally visit - I'm learning C# for Unity, but c2 is still a respectable game engine imo....
B
73
S
19
G
66
Posts: 2,198
Reputation: 42,188

Post » Sun Dec 22, 2013 2:01 am

[QUOTE=mindfaQ] Shadows add on top of each other, should fix that./QUOTE]

Easy fix.

In the events, it's set up to change the transparency to 40%. Remove that.

Go to the Shadow layer, and change the layer transparency to 40%.

Problem solved.

Unfortunately, with this it makes it harder to allow the shadows to appear on top of objects, otherwise you could also add in an event that detects if the robot is lower than the object, and have that shadow move to a higher layer.
@bearboxmedia
www.bearboxmedia.com

Nintendo Wii U Developer using Construct 2
B
79
S
12
G
7
Posts: 961
Reputation: 10,717

Post » Sun Dec 22, 2013 2:08 am

@AnD4D,

Every day is a school day - and thank you for the help. I'll have a look at the easy fix now and update the tutorial - it didn't occur to me to manage the transparency that way (clever - I like it). The multi-layer option for shadow casting over other objects will require some thought on my part but it sounds good...

Ed
I only occasionally visit - I'm learning C# for Unity, but c2 is still a respectable game engine imo....
B
73
S
19
G
66
Posts: 2,198
Reputation: 42,188

Post » Sun Dec 22, 2013 3:14 am

OK, I've updated the capx and tutorial. Now you can select one of 2 groups in the capx. The first puts the shadows onto a separate and lower layer that has its opacity set as suggested by @AnD4D (no darkening of shadows on overlap, but the shadows don't cast onto other objects). The second option group (enabled on capx download) puts all shadows and objects onto the same layer and order their z position according to y position so that the shadows do cast onto objects that are apparently underneath them. It's not perfect but much better, I think - thanks for the ideas.Colludium2013-12-22 03:15:15
I only occasionally visit - I'm learning C# for Unity, but c2 is still a respectable game engine imo....
B
73
S
19
G
66
Posts: 2,198
Reputation: 42,188


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 7 guests