How do I access collided family's object?

Get help using Construct 2

Post » Wed Jun 18, 2014 5:37 pm

I have condition:
If object of family "A" is overlapping another object of family "A", then create revolute joint from one to another.
Image

1 - works
2 - doesn't work

It takes all the objects of this family with boolean set to false, so when i have just one object of this family with boolean = false and multiple objects of this family with boolean = true, it correctly picks this one particular object. But how to create joint from it to another object of the same family (these with boolean = true)?
B
5
Posts: 9
Reputation: 243

Post » Thu Jun 19, 2014 1:14 am

Use a second family with the same objects in it. Then you check family A against family B.
ImageImageImage
B
71
S
22
G
257
Posts: 3,790
Reputation: 142,696

Post » Thu Jun 19, 2014 4:39 pm

I'm afraid that it'll not work in my case - objects of family A are objects for placing in world and are created at runtime. Example with building a wall:
1. Object "brick" from family "Placeable" is picked by clicking a button and created in layout.
2. "brick" is placed on ground and it changes it's variable "placed" to true.
3. Another "brick" is picked (and created at runtime) - now, i want to place it on top of previous "brick" (in my case, when they're overlapping, so it's like welding) System correctly detects when they're overlapping, but it doesn't create revolute joint to this previous brick.

I've thought about having another family/container with only "placed" objects and checking against it, but it will need possibility to add objects to family/container at runtime - and right now it's impossible, am i right?

(That was only a exmaple, in my case i need a limited revolute joint)
B
5
Posts: 9
Reputation: 243

Post » Thu Jun 19, 2014 4:54 pm

Families have nothing to do with instances. You have a Family now, You can make a second duplicate, and it will work the same way.
ImageImageImage
B
71
S
22
G
257
Posts: 3,790
Reputation: 142,696

Post » Thu Jun 19, 2014 5:25 pm

OK, I've just changed my mechanics so i don't need this approach anymore, but thank You :)
B
5
Posts: 9
Reputation: 243

Post » Thu Jun 19, 2014 5:43 pm

ye, the timing.
B
15
S
3
G
5
Posts: 396
Reputation: 4,977

Post » Thu Jun 19, 2014 6:42 pm

blackhornet wrote:Families have nothing to do with instances. You have a Family now, You can make a second duplicate, and it will work the same way.


It depends... You can't actually duplicate a family if it has family instance variables. If, in his example, the "Placed" variable was an instance variable of the "Placeable" family, then he can't duplicate the family to use that trick, because objects can't have 2 instance variables of the same name, so the second family can't have the "Placeable" instance variable, and then you won't be able to access the "Placeable" variable of any object in the duplicate family.

The OP's problem is actually one of the reasons why I suggested having aliases in Construct 2 (topic: https://www.scirra.com/forum/construct-2-general_f146?start=25), but @Ashley already dismissed my idea because of performance issues. Maybe if the engine supported somehow assigning object references to local variables, or some kind of "ObjectReference" plugin which serves the same purpose.

In any case, OP, how did you sidestep the issue? It would be useful to know for future reference
B
6
S
2
Posts: 79
Reputation: 608

Post » Thu Jun 19, 2014 7:34 pm

Yeah, object references, maybe possibility to create local variables of any object's (family?) type (not only boolean, float & string) will be very useful. It's quite hard to get into some Construct 2 areas when coming from object-oriented programming :P
As to my issue, i've re-categorized a lot of objects (it's not exactly about building walls) and changed whole gameplay a bit, but basically i'm creating an extra empty sprite (collider) in place where any of placeable items is placed - and every new placed object creates a joint to these colliders (so it's checking for overlapping with these colliders, not with "Placeable" objects)
Maybe not a perfect solution for building structures, but works in my case.
B
5
Posts: 9
Reputation: 243

Post » Thu Jun 19, 2014 8:08 pm

Just FYI, I think this topic is covered here: https://www.scirra.com/tutorials/556/un ... o-families
Image
B
10
S
3
G
2
Posts: 196
Reputation: 2,053

Post » Thu Jun 19, 2014 9:52 pm

Dalal wrote:Just FYI, I think this topic is covered here:


While that tutorial is extremely helpful, it doesn't solve this particular problem, because the "Create limited revolute joint" action on the Physics behavior takes an 'object reference' as a parameter, which you don't have when using the solution the tutorial proposes.
B
6
S
2
Posts: 79
Reputation: 608

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests