0 Favourites

How do I duplicate ragdolls [SOLVED]

  • Hi everyone. I'm new to Construct 2 development.

    I like how one can make complicated things in 2 clics, but unfortunatly, I'm struggling with somewhat simple things since several days...

    So here it is: I'm making a game with ragolls falling from the sky. Lots of ragdolls.

    My problem is that I have no idea how to duplicate them (AKA system/create).

    Do I have to attach each limbs again after having created the ragdoll?

    Thanks for your help

  • One way would be to put all of the rag doll elements into one Container. Then have a Function that is called when On Create RagDollHead is triggered (assuming RagDollHead is the parent of the container); you only then need to place/create the RagDollHead sprites on your layout and the Container will take care of the rest. In the On Create Function you'll have to code the positioning of the limbs and creating the joints etc, but you'll only have to code it once in your game.

  • Could you not just spawn the container, and that container have the 'connected up ragdoll' in it? Or is that not possible?

  • Not an option - the container only lists the sprites that are associated with each other. You've still got to tell the physics engine how to connect them together.

  • Hi, thanks for your help!!

    So I used container and function but I have trouble attaching the limbs correctly to the body. It don't seems to take the set angle into account. Furthermore, attaching limbs to the body seems to give it some force at a random angle. Or maybe is there something that I don't understand?

    I've attached a short exemple. Just press spacebar to create a ragdoll.

  • Help, I'm still trying to attach the limbs correctly to the body once it has been duplicated...

    I've tried "set position" or "set position to another object" but nothing is taken into account, and the body appears with a force that seems to be related to the limbs attached to it... I don't understand.

    Thanks for your help !

  • Hi, I've spent one week trying to attach the limbs correctly to the duplicated ragdoll without luck.

    It should be very basic but I don't understand the logic here.

    The limbs don't take the position into account and they're giving a force to the body when they are attached to it...

    Here's a simple example, with only the body and the head, you'll see what I mean.

    Does anybody know how to do that please?

  • Txori,

    I've fixed it!

    Some comments for your future enjoyment of programming with C2:

    • Take a good look at the shapes of the arms and legs - you had them as squares and stretched them in the editor. They looked ok but I'm not sure this stretching was helping the physics engine.
    • The head object you had was 256x256 and was shrunk in the editor. Again, not sure what that would have done to the physics engine, so I resized it to 30x30.
    • The image origins are now positioned on the right/left limbs at where the joint should be - you had them in the center. This was causing the physics joint to link from the body imagepoint to the center of each limb rather than the shoulder/hip.
    • I have shuffled your events around a bit. Now you have an on-create event that positions everything properly once the body is created. In hindsight this might not be required, but for the point below you can't create everything in a Function (unfortunately).
    • The on-create body event now has a 0.05 sec delay - this allows the physics engine to catch up with the new objects it has to consider. It doesn't work if you remove this. Luckily you can't notice this.
    • I've used a container to contain all of the limbs to minimize code.

    Here's the finished capx - enjoy!

  • Thank you so much Colludium!

    I've learn so many things with your explanations. As I started from the example given with Construct 2, I thought that square and stretched limbs would work. And I would have never find out about the .05s time delay...

    I'll make a good use of your example!

  • Sorry but after a lot of tries in my game, I still have weird behaviors with the physics...

    So I went back to your exemple and I deactivated the limbs to keep only the head to discover what's going on.

    You'll see that the only ragdoll with the head in the correct place is the first one. The others have the head far from the body. Here it's not really a problem, but in the game I'm trying to make, it's very visible since the body have a neck...

    I've spent several hours today trying to comprehend what is going on. Is that some kind of weird bug in Construct 2?

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • So after a bunch of more tries, it appears that

    Head - Set position (Body.X, Body.Y-10) works, but

    Head - Set position (Body.ImagepointX("head"), Body.ImagepointY("head")) won't...

    Seems like a Construct bug to me. Either way, I'll try that solution in my game and see if it finally works.

  • It seems to work fine for me. If you disable physics on each limb and the body and then try your example again you can see that the head is set to the correct position each time. Maybe you need to move the "head" imagepoint inside the body to change where the head is positioned to. Otherwise I'm not sure what the problem is...

    PS you need to add Colludium to your message or I won't get a notification that you're looking for more help.

  • Oh ok

    So Colludium , I've prepared an example with the ragdoll I'm actually using in my game. You'll see that only the first one is ok and the others are quite messed up... You can move them using the arrows, try to keep the good looking one alive

    Edit:

    here's my last thought, maybe the problem comes from the limbs that are overlapping the body for a perfect connection? Maybe the bounding boxes don't like that...

  • There are 2 problems.

    One is an error in the events - you position the DudeRightCuisse to an imagepoint on itself....

    The second is caused by the container and is part of what you identified above. When the body is created, the container causes all of the limbs to overlap on top of each other - the physics engine then immediately tries to move them because they are in collision. When the joints are created, the limbs have moved from their desired positions by this movement and that's why the subsequent dolls are funny shapes.

    Part of the fix to the second problem you have already identified - make sure that the collision polygons are not overlapping when the limbs are in position. You also need to have the physics turned off for the limbs until they have been moved from being in collision when they are created by the container. Once they have been correctly positioned you can turn their physics on.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)