Detect Shadow Collision

Get help using Construct 2

Post » Fri May 19, 2017 6:58 pm

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.
I'm seeking Narnia. Who wants to come with me! Aslan is on the move!
B
141
S
24
G
8
Posts: 791
Reputation: 15,121

Post » Fri May 19, 2017 7:47 pm

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.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Fri May 19, 2017 7:49 pm

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.
I'm seeking Narnia. Who wants to come with me! Aslan is on the move!
B
141
S
24
G
8
Posts: 791
Reputation: 15,121

Post » Fri May 19, 2017 9:18 pm

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.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri May 19, 2017 10:07 pm

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.
I'm seeking Narnia. Who wants to come with me! Aslan is on the move!
B
141
S
24
G
8
Posts: 791
Reputation: 15,121

Post » Fri May 19, 2017 10:21 pm

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.
Follow my progress on Twitter
or in this thread Archer Devlog
B
41
S
18
G
18
Posts: 1,025
Reputation: 13,347

Post » Fri May 19, 2017 11:34 pm

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.
I'm seeking Narnia. Who wants to come with me! Aslan is on the move!
B
141
S
24
G
8
Posts: 791
Reputation: 15,121

Post » Sat May 20, 2017 9:38 am

LOS has a range.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sat May 20, 2017 1:41 pm

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.
B
94
S
33
G
113
Posts: 5,356
Reputation: 73,273

Post » Sat May 20, 2017 3:29 pm

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.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 15 guests