Swinging Traps Issue

I’m making a platform game, and I am trying to make a chain that swings from an anchor point. But some parts of my chain just fall, and the rest get stuck. Any help would be appreciated.
(The Code I am Currently Using)


(Chain In Game After Launch)

(Chain In Editor Before Launch)

Chain demo

1 Like

Thank you, but I have tried everything from the demo thats how I’ve gotten this far. I just can’t figure out what i’m doing wrong.

Did you check behaviors and variables tabs of each object?


1 Like

This is how I have them set, far as I could tell they are right. Idk Tho, I’m still new to this.
(Link1 Variables)


(Link2 Variables)

(Both of the physics are the same on both links)

(Anchor Physics)

(Anchor Variables)

I’ve been playing around with the concept and I think I found a simple way that for the most part sets itself up. I’d like to modify it to add the links at runtime but this works really well.

Try me: (the black follows the cursor for integration)

source:

The setup is fairly simple. It uses 4 sprites. A mount, a side link, a front link and a ball at the bottom. Plus, a frame object which is used to select a matching set. Instead of IDs, I switched to nearest from right above the mount. I didn’t use the mount itself because it needs to be picked as well. As it picks the nearest, they’re filtered out as the JointID is set to the objects.

My original version used a bunch of variables, but I haven’t cleaned them up yet. The only one it needs are the sceneJointID and object JointID. There are 2 groups. One with everything, one with the mount, front link and ball. They all have the physics behavior. I only changed the setting on the mount to “static”. There are top and bottom points on each object for the joint location.

Edit: There is a newer version on the bottom. I didn’t want to change this because this version matches the GitHub version. I’ll try to rewrite this post tomorrow.

The chains can be any length as long as they are base, any quantity of (side then front ) and then ball. Plus, they need to be inside a frame. The frame is just for setup and can be hidden and or deleted after setup.

Using a Boolean definitely makes more sense. I’ll update everything tomorrow.

3 Likes

I created a version that adds the links at runtime based on the position of the mount object and using its quantity variable. You just need to add a mount object and set the variable.

1 Like

What could make it not load up at all I tried using the example code and made all my objects the same way, but the chain isn’t loading up at all now?

There’s a lot to set up but then it’s fairly automatic. The objects that face sideways need to be in the group. I say sideways which might not have been the correct term but it’s a matter of perspective. When I say side ways, I mean the mount, the ball and the link that faces in the same orientation. They all have a hole. The other link should not be in the group. It’s the narrow one without a hole.

The objects all need points although without the point it would still join them but use the origin point. I believe.

The mount has to have the Quantity variable. I’m not at my PC but the variable needs to be spelt the same way including case. All the objects need the physics behavior. The only setting I changed was setting the mount object to static.

Otherwise, it’s just a matter of having the same events. With a mount object in the scene with the Quatity set to a number >0

If you post a screenshot, I’ll take a look.

1 Like

i copy and paste the code changed all the names of my objects. and i figured out why it wasnt showing up. but now its just swinging in circles super spread out and messed up

it was hard to catch the actual chain because u can only see 1 piece and it flashes back and forth really quick. but its in the bottom left area outside the wall when it shows up

the ball just swings in circles

I can’t tell anything from the picture. Is it working at all? Are you adding force to make it swing? If so, does it work without force?

Honestly, as cool as a real looking chain is, it might be simpler just to have a rigid image of a chain and ball swinging from a point.

I’ll still try to help either way. I’m curious as why it’s not working.

1 Like

Ball Physics


Ball Variables (same as both link Variables)

Ball Points

Link Physics (same for all links)

Link Points (same for all links)

Mount Physics

Mount Variables

Mount Points

Groups


Scene Variables

I think there are 2 issues. I prefer to have my origin point in the center of the object. IDKW, I just do. When I set my origins on all of the objects the longest chain freaks out. I’m guessing it’s the placement.

The other issue might be the difference in image size. My doodles were much larger than your beautiful images. That might be messing with the placement. You can try either changing the origins or the values for the placement.

My original strategy was to place the links exactly where they need to be but I decided to add 15 to each Y(). I remember why I used 15. You can’t get the Point locations for an object that doesn’t exist yet.

You’ll need to figure out the math so when the objects are added they’re in the right location. They’ll spring together as long as another link isn’t in the way. Your objects are much smaller and efficient because I never trimmed the excess parts from my images. Everything is just slightly different. Your links are round/square while mine are longer rectangles.

I’ll adjust the size of my images and see if I can get the right math as well just in case. Also, to make it more user friendly. It should calculate the number instead of using fixed numbers. Maybe if I add the object off screen and then read the value first. IDK. it needs tweaking.

1 Like

This is not something I’m fixing today. For some reason they’re extremely fragile when they’re small. I even tried copying the physics setting from the Gdevelop example. They seem to fall apart when I barely touch them. Something isn’t right.

Edit: I moved the top and bottom points away from the edge and the chains are much stronger. I’m wondering if they need to overlap more to stay linked. Maybe that is how the joints work. My links were huge and had a lot of overlap.

1 Like

I think I sort of know what was going on. The objects need to overlap. I added 4 empty pixels to the tops and the bottoms of the links. That allowed me to link the object 4 pixels from the edge. I added an offset variable to debug the setup. I also added a Boolean so I could test it without the objects moving.
The links or joints still seem a bit weak.

Current version.

I also disabled the layer and mask for everything but the ball. That way the chain can’t collide with itself , the mount or the ball. The chains seem much smoother.
image

Try me. press the mouse button to be able to push the ball.

1 Like

So far that works better I just can’t figure out how to make my chains longer. and what controls the quantity variable. like how does it know there’s more than 1 mount?

It uses a for each obj for the mount object and the mount object has a quantity variable for the number of links.

1 Like

I also noticed if I manually change the variable quantity to anything more than 7 my chain becomes extended at the start and stretches off the map. It’s stretched out at start no matter the quantity variable, but it comes back together if it’s lower than 8. 8 and above make it stretch off the map. but it to short at 7 for me to really use.

As much as I love the look of a real chain, I don’t think the joint, at least not this joint, is stable enough. A tiled sprite of a chain or a panel sprite could look just as real if it just rotates around its origin.

If you used a regular sprite, you could add some randomness to the chain animation to make it look like the links are moving.

Honestly, I love the chain concept. I just don’t think it’s worth the effort if it’s just a small portion of a much larger game. It would be one thing if it was the main theme but not for just a trap. The player isn’t going to appreciate the accuracy but they will freak out if the chain falls apart.

I don’t know if another joint would be more stable or if there’s a way to fake a joint. I just don’t think my method works for this situation. I’m disappointed.

If I have the time. I’ll continue to play with it but I just don’t think I can make this work with the joint. It seems to require an overlap. Maybe the distance or one of the physics setting can be adjusted. I don’t like to give up but sometimes you need to know when to try something else.

1 Like