#(conceptually) How do I code a tension system (body with 3 springs)

10 messages · Page 1 of 1 (latest)

bronze parrot
#

I'm looking for some advice on how to program the physics of an object being pulled by 3 or more different pistons/springs/lines/ropes attached to it, allowing the object to move, and rotate based on where the "feet" of these 3+ "legs" are. I have no idea where to start with the physics, though i think i have a quite optimal scene tree layout for the body and legs, including the points of attachment, and the feet of the legs.
thanks for any help about how to go about this, i am so lost.
@me please.

bronze parrot
#

Oh pshhh I forgot I posted this.

spare raptor
# bronze parrot I'm looking for some advice on how to program the physics of an object being pul...

What a cool idea!

I think this may be beyond me (I failed physics class 😂), but I can imagine how I would make such a system.

First to help myself I am going to rename legs and feet to ropes and posts bc I have an easier time visualizing that. However "post" may not be the best term either because you might want them to move.

So each rope has a tension variable that can be determined by the distance between the post and the object, the longer the distance, the greater the tension.

Next, each rope will have a direction to apply that force, which can be determined using Pythagorean theorem with the object location and post location.

In godot we apply movement using "velocity = speed * direction". By applying this we should be able to move the object in the right direction at the right force.

bronze parrot
#

I kind of got it working. Not exactly as described but I like how it turned out. 🤷‍♂️

spare raptor
#

Yoooo thats awesome!!! godette_scared

#

Now I see why you called them legs and feet lol

bronze parrot
# spare raptor What a cool idea! I think this may be beyond me (I failed physics class 😂), b...

I used 3 Dampedspringjoint2D’s but I think if I did it again, i would code it from scratch. The spring joint has had known issues for a long time, and one of those issues is that you can’t set a hard maximum. I could’ve just calculated a midpoint between all the feet every frame and set that as the target position of the body node, and then I wouldn’t be fighting Inc with the spring physics. I’d then attach that point to the body with a spring…

This might not work with rotation though, so I’m not sure that would be the right decision either, in reality.

I feel like the best solution is spring + custom code, but I’m not sure how to code it right. Get the global mouse position.direction_to(body node) and then set the length of that vector2 to the distance from the body that the mouse is minus the maximum distance, then I add that Vector 2 to my current mouse position, and that becomes the glibal_position data for where the foot should be.

#

But it’s been being weird after you reach that point (is looks like it jump 20-30 pixels ahead of your mouse.

#

So I’m not 100% sure what the fix it.

bronze parrot