How do I detect collisions between two SPECIFIC instances

Get help using Construct 2

Post » Fri Feb 06, 2015 12:26 pm

how do i detect a collision between two specific instances of the same object type?
i say specific because ive seen posts that just want to differentiate values of their instances but
i want to detect a collision only between for example sprite with UID 1 and sprite with UID 2,
or sprite with instance variable 1 and sprite with instance variable 2
both sprites being of the same object type of course
B
3
Posts: 9
Reputation: 193

Post » Fri Feb 06, 2015 12:45 pm

Not sure if there is regular way, although I believe you could "cheat" here.
Create 2 families, and in both put objects you want to collide. Then pick by first UID first family, by second UID pick second family, and them detect their collision.

They will be objects of the same type, by defined by different family.
B
12
S
6
G
2
Posts: 99
Reputation: 1,727

Post » Fri Feb 06, 2015 1:16 pm

i sort of made it with events although not elegant:

create variable
when sprite is overlapping sprite
pick sprite by evaluating IID=0 > add 1 to variable
pick sprite by evaluating IID=1 > add 1 to variable
variable = 2 > do event then set variable to 0
else set variable to 0

this is really not the solution i hoped, it should be:
if sprite.IID(0) is overlapping sprite.IID(1)
B
3
Posts: 9
Reputation: 193

Post » Fri Feb 06, 2015 2:54 pm

I believe your solution is more hardware demanding because it checks for all collisions and then looks if any collision that happens is the right collision.

With familliy trick you can pick right instances and then look just at collision between these two.
B
12
S
6
G
2
Posts: 99
Reputation: 1,727

Post » Fri Feb 06, 2015 3:59 pm

follow me here:
Sprite -> On collision with Sprite
System -> Pick Enemy by evaluating Sprite.UID = 1 | Sprite.UID = 2
System Enemy.PickedCount = 2

What do you think, blah6546? Those three conditions all go in one event.
B
11
S
4
Posts: 152
Reputation: 1,236

Post » Fri Feb 06, 2015 4:46 pm

you know you could try to use instance variables
B
5
Posts: 60
Reputation: 345

Post » Fri Feb 06, 2015 5:00 pm

Ash10500 - he already uses UID

Unnatural20 - in that case it will check all collisions which will eat more resources.

Best way would be to first pick 2 objects by UID and then check only these two object for collisions.
B
12
S
6
G
2
Posts: 99
Reputation: 1,727

Post » Fri Feb 06, 2015 5:23 pm

i was about to say that it doesnt work but i was confusing "pickedCount" with "count" aghh
for some reason i cant see the expressions panel anymore, but yes it does work, perfect,
also i was going to suggest inverting the order of events but i wanted to test it first and it doesnt work for some reason

[EDIT1]
actually it does work but with subevents:
system pick sprite by evaluating sprite.IID=0|sprite.IID=1
[subevent] sprite is overlapping sprite
---system sprite.pickedCount=2

brilliant, thanks

[EDIT2]
"system > sprite.pickedCount=2" doesnt seem to be necessary in this arrangement
B
3
Posts: 9
Reputation: 193

Post » Fri Feb 06, 2015 5:41 pm

bla6546: Ooh, yeah, your solution is even better. Fits RazorMonkey's advice of only checking the collisions of those sprites in particular. You shouldn't even need a subevent; but you might want System -> Trigger Once While True

I've been testing this on a demo I threw together for another problem someone was having, but check it out:

When the first two Enemies first are overlapping, they flash for a second.
You do not have the required permissions to view the files attached to this post.
B
11
S
4
Posts: 152
Reputation: 1,236

Post » Fri Feb 06, 2015 6:00 pm

actually you can substitute the variable and the first two events with:

enemy is overlapping jail > set text to enemy.pickedCount
B
3
Posts: 9
Reputation: 193

Next

Return to How do I....?

Who is online

Users browsing this forum: Arekusei, R0J0hound, UncleHo74 and 0 guests