Create joints between two instances of the same object

Hi all!
If I create multiple instances of an object that use the physics engine, how can I connect the instances to each other with joints?
Since they all have the same name but different ID (object variable) I cant find a way to connect them with joints. Joints only seem to use object names to connect ot each other. I am trying to create a fishing net, as in the image below, but a much bigger net, that moves naturally in the water.

Cheers

Farid

1 Like

Interesting position you’re in. I’d look at having 2 objects; one a duplicate of the other. Then set them up alternately (kind of like a chess board) as the net-thread intersections.

Good idea!
I guess I need to create both instances before I can connect them. After doing that I would need to reference them using their object name and object variable. But I can’t figure out how to write an expression that use the object variable. The only parameters I can find are the points of the original object.

Cheers

Farid

I’m calling the object that represents the net thread points a connector.

Give each connector an increasing ID from left to right, top to bottom (so top row from left to right is 0, 1, 2, 3…n, second row is n+1, n+2, n+3 etc)

Then run 2 loops - one for horizontal connectors, the second for vertical connectors. Something along the lines of this (I’ve assumed 6 columns with 4 rows of connectors based on the image in your first post) :

Wow, thanks so much for helping me out!!
For some reason I’m bad at understanding screenshots of event sheets so I hope I’ll manage to figure out what you have done. Anyways, this will help me forward. Thanks again!

//Farid

Have a look through it and then let me know what parts you don’t understand, and I’ll see if I can explain them.

1 Like

Hi again MrMen,
First question. The first event where you create the variables seem to be repeated. I guess there is a missing “At the beginning of scene”?

Second, you have made a “Repeat Variable(colCount) times:”
-How do you do that? The only repeat I can create is “repeat for each instance” where I have choose an object. Not a variable.

Also you have made a “Repeat Variable(rowCount)- 1 times:”
-What does that mean? Repeating one time is like not repeating at all. Also, the minus (-) makes it negative. Repeating negative times makes no sense to me. I just don’t understand what the code is doing and I don’t know how to create it.

Thanks

Farid

Yes, all the events in my screen snip should be subevents of a “At the beginning if the scene” event.


Use the Repeat event :

image


It means to repeat it rowCount-1 times. So with the net, it’s be 3 times, or the top 3 rows of the net.

It’s linking each connector in the row with the one below it. We only do the first 3 row (out of 4), because the last row doesn’t have any connectors below it.


So, I started to explain using this visual, with each number representing the ID of the netLine or NetLine2 object :

image

Each even numbered connector is a netLine, and each odd connector is a netLine2.

And at this point I realised I’ve missed 2 events. I’m about to head to bed, so I’ll fix it in the morning and update this thread.

Sorry, I’ve taken longer to respond than I had planned.

Replace this event :

with these :


And this event :

with these events :


I think that should do it.

Wow, thanks MrMen!
I’m working with another project for a few day right now so no worries about taking your time. I’ll take a look at your code and test it, asap.

Cheers

Farid

Hello again @MrMen,
Finally I think I have managed to recreate your code. I hope I have done it correctly. But I guess that I didn’t manage to create the IDs as you suggested, with n+1, 2, 3…

Anyways here is my attempt, but so far it is not working :frowning:

What am I missing?

Cheers

Farid

Edit:
One more thing…
Should I use points when connecting the netLines? Like “Left” and “Right”.

You’re creating the netLine and netLIne2 objects at 600,700. They need to be in their correct position before you add the rope joints. Otherwise GDevelop will try to maintain a rope distance of 0 pixels.

Also, what you will probably get is that the net folds in on itself. You may need some type of force or joint that causes the bottom left and bottom right netLines to go out and down further, to keep the tension on the net and keep it spread out.

Imagine it like a sheet of cling-wrap plastic that’s just been taken off the roll. You need to pull it apart to get it into it’s shape again. The same has to be done here with the netLine connections.

Ok,
That complicates things even more. Maybe I can use the “Create multiple copies of an object” extension, since it creates objects in a grid and also seems to create IDs for the instances. Actually I feel that I’m a bit over my head with this. I can’t even create the IDs of the instances. Maybe I should create a separate question about that, since it’s such a basic issue.

Cheers

Farid