Object collision with itself

Discussion and feedback on Construct 2

Post » Mon May 19, 2014 3:24 am

So I'm using a single object for each unit in a strategy game, using local variables to distinguish the team. I need a method to determine if it is overlapping another object of itself, but only if that object belongs to the other team. I'm not sure how to test this specifically.

For example, I need:

If unit with team = 1 collides with unit with team = 2, then trigger. This should be simple but the overlapping event is limiting me and I'm not sure what to incorporate to overcome this.

Thanks!
B
72
S
24
G
11
Posts: 452
Reputation: 12,380

Post » Mon May 19, 2014 3:41 am

This has been brought up a million times and there has never really been a definitive solution. We desperately need some more options here! Ideally we could do something like...

+If Instance (with value of x) collides with Instance (with value of y)
-Pick Instance (with value of x) and do this
-Pick Instance (with value of y) and do that

You might be able to pull it off with functions or something but eh...good luck.
Image
B
243
S
30
G
13
Posts: 1,787
Reputation: 18,770

Post » Mon May 19, 2014 4:17 am

Could you just spawn an pin and invisible sprite over each team object. Team 1 gets invisible sprite 1 and team 2 get invisible sprite two and when the two invisible sprites overlap you you know its the condition your looking for?
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Mon May 19, 2014 5:05 am

This can be done with Families.
ImageImageImage
B
71
S
22
G
247
Posts: 3,756
Reputation: 137,558

Post » Mon May 19, 2014 3:55 pm

Yeah, just have sprite, put it in a family by itself, and give that family a variable named team. Now both sprite and sprite_in_family have the variable team and you can check if sprite is overlapping sprite_in_family and if sprite.team=sprite_in_family.team. I've got it working this way in my game Shards.
Moderator
B
95
S
34
G
33
Posts: 3,007
Reputation: 27,876

Post » Mon May 19, 2014 4:05 pm

Alternatively you can use 'pick nth instance'. 0th and 1st instance can then be referenced individually.
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,699


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 10 guests