Can an instance detect itself on overlap?

For questions about using Classic.

Post » Thu Oct 29, 2009 3:35 pm

Here's what I have:

Spider is in Family Bugs. I want Splatter to spawn only when the the Spider is destroyed and is overlapping anything in the Family Bugs. However, even if the Spider is alone, it still spawns Splatter. Is this because Construct reads the Spider as overlapping itself (because it's in the Family Bugs)? Is there a simple way around this?

Here is my code

[Condition]When Spider Life=0:[Event] Destroy Spider
[Sub-condition]If Spider overlaps Bugs:[Event] spawn Splatter

Thanks in advanced!
B
51
S
13
G
8
Posts: 194
Reputation: 7,311

Post » Thu Oct 29, 2009 3:43 pm

It's being asked all the time in one form or another. Should be sticky somewhere or something I don't know.

Add another family to your Spider sprite. Now check for overlap between those two families instead of using the sprite itself and one family. Should work like a charm now. :D

So your events could look like this (while Vermin is the new family):

[Condition]When Bugs Life=0:[Action] Destroy Bugs
[Sub-condition]If Bugs overlaps Vermin:[Action] spawn Splatter
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Post » Thu Oct 29, 2009 11:01 pm

You can also have your variable comparison in the same condition with is overlapping.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Thu Oct 29, 2009 11:28 pm

Thanks for the quick reply. Works perfectly. :)
Sorry for asking a question that's been answered many times before :oops:

The condition here is "Sprite is overlapping another object" but logically, I think, "There is no other object!" So I'm curious as to what example is happening inside of Construct. Construct is usually very transparent (which is why it's so easy to use), but this one has me a little puzzled.
B
51
S
13
G
8
Posts: 194
Reputation: 7,311

Post » Fri Oct 30, 2009 11:23 am

Hmm, this sounds like a bug. It makes no sense for an object to register as overlapping itself. Put something on the bug tracker so I don't forget about this one.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478

Post » Fri Oct 30, 2009 11:41 am

If an object is checking for overlap with family it is in, it doesn't check if it is overlapped the family counterpart of itself. I've made it a habit to compare the UID; only go ahead with overlap detection if the UID is different than the object's.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Sat Oct 31, 2009 11:26 pm

I just made a quick .cap in 0.99.5 - 'Sprite overlaps family Red', and Sprite is in family Red. The event never runs. In the runtime, I can see I have already accounted for the overlapping-self case and made sure its never run. Can someone reproduce this in a simple .cap?
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478

Post » Sun Nov 01, 2009 12:46 am

Strange, I just did the same and it works fine.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Sun Nov 01, 2009 9:19 am

I was trying to reproduce my problem again and was having trouble doing so as well. I went back into a old copy of my game and realized that the spider hit box that was always set to the spider was mistakenly in the family bugs, causing the on collision to occur all the time.

My mistake. Sorry to throw you guys for a loop :oops:
B
51
S
13
G
8
Posts: 194
Reputation: 7,311


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 0 guests