Page 1 of 3

Fast Rope Physics for bump.lua?

Posted: Sat Mar 13, 2021 4:58 pm
by Gunroar:Cannon()
Hello there. I'm looking for help with coding a rope and rope physics that doesn't use love.physics and that can be attached to 2 objects which cause the rope to be pulled and the object to pull one object in a similar way. I've seen other implementations but does anyone have an implementation that can do this.
The pulling should be realistic(damping? I'm not sure how it works) and also stop when the object being pulled is behind a wall/obstacle.

Re: Fast Rope Physics for bump.lua?

Posted: Sun Mar 14, 2021 5:34 pm
by MrFariator
You could do this with bump, but I think you'd honestly be better off using love.physics/box2d for any realism. After all, bump.lua's README even says:
bump is not a good match for:

- Games that require polygons for the collision detection
- Games that require highly realistic simulations of physics - things "stacking up", "rolling over slides", etc.
- Games that require very fast objects colliding reallistically against each other (in bump, being gameistic, objects are moved and collided one at a time)
- Simulations where the order in which the collisions are resolved isn't known.
The first three points are pretty relevant for rope physics, and maybe 4.

However, if you want more gameistic ropes? Sure, bump should work fine. Maybe illustrate an example of what the rope system needs beyond damping.

Re: Fast Rope Physics for bump.lua?

Posted: Sun Mar 14, 2021 6:04 pm
by 4vZEROv
Sound like inverse kinematics

I've made some prototype that look like that: https://twitter.com/4v0v_/status/1334771338020593666

If it look like what you want I can try to find the code.

Re: Fast Rope Physics for bump.lua?

Posted: Sun Mar 14, 2021 7:11 pm
by pgimeno
T2R uses a simple rope, with just 1 segment, to attach the ball; feel free to check the source code (see sig). If you want a more realistic behaviour (catenary effect, for example) then the plot thickens.

Re: Fast Rope Physics for bump.lua?

Posted: Mon Mar 15, 2021 8:56 am
by Gunroar:Cannon()
I kind of just want the object to be dragged by another object, like their in tug of war, but with no extra stuff like yoinking due to gravity.
4vZEROv wrote: Sun Mar 14, 2021 6:04 pm Sound like inverse kinematics

I've made some prototype that look like that: https://twitter.com/4v0v_/status/1334771338020593666

If it look like what you want I can try to find the code.
This seems like it might work, can you find the code?
pgimeno wrote: Sun Mar 14, 2021 7:11 pm T2R uses a simple rope, with just 1 segment, to attach the ball; feel free to check the source code (see sig). If you want a more realistic behaviour (catenary effect, for example) then the plot thickens.
Yes, the plot thickens :rofl:

Re: Fast Rope Physics for bump.lua?

Posted: Mon Mar 15, 2021 12:30 pm
by pgimeno
Gunroar:Cannon() wrote: Mon Mar 15, 2021 8:56 am Yes, the plot thickens :rofl:
If you want pre-made code you can check this project for example: viewtopic.php?f=5&t=12330

If you want to know what you're doing, I suggest you take a look at this post: viewtopic.php?p=219275#p219275 (maybe you need to read some earlier posts for context).

Basically, a rope can be modelled as a series of springs attached to each other, similar to the image here: https://en.wikipedia.org/wiki/Wave_equa ... ke%27s_law so you would use Hooke's law to adjust the position (for each spring in the rope, correct the position of the mass at the end, by applying a force proportional to the distance difference from the "default"/"relaxed" distance). You need to use Verlet integration and make multiple passes. You also need to apply gravity to each mass for the catenary to form itself.

Re: Fast Rope Physics for bump.lua?

Posted: Mon Mar 15, 2021 7:57 pm
by Gunroar:Cannon()
Nice, I'll look into those thoouugh...I really want my rope to be simple, like straight lines that only bend when they go around a corner(so you could say the physics part is when it comes down to other objects pushing each other. That's why I wanted it done in bump :rofl: .The "rope" should bends only when it goes around a corner.
That's why I found it hard to use the normal algorithms I already found(plus its for top down use, so no gravity)...heheh.
So with this said any new ideas, or can it still be done with the other ropes?

Re: Fast Rope Physics for bump.lua?

Posted: Tue Mar 16, 2021 6:18 am
by RNavega
You could port some Verlet engine into Lua, the rope would consist of several linked segments (like 100 total), each with a distance constraint.

There are tons of live Verlet physics demos online using HTML5:
- https://subprotocol.com/system/tree.html
- https://codepen.io/guerrillacontra/pen/XPZeww
- https://codepen.io/CLMcCorkle/pen/vrxrgE

Plus this Love2D reference (thanks to GloryFish):
https://github.com/GloryFish/love2d-verlet-cloth

Re: Fast Rope Physics for bump.lua?

Posted: Tue Mar 16, 2021 1:53 pm
by pgimeno
Gunroar:Cannon() wrote: Mon Mar 15, 2021 7:57 pm Nice, I'll look into those thoouugh...I really want my rope to be simple, like straight lines
Now I'm lost about what you want exactly, as this contradicts the ropes forming a catenary and all that.

Gunroar:Cannon() wrote: Mon Mar 15, 2021 7:57 pm that only bend when they go around a corner(so you could say the physics part is when it comes down to other objects pushing each other. That's why I wanted it done in bump :rofl: .The "rope" should bends only when it goes around a corner.
Bump only handles rectangles, specifically axis-aligned ones. I don't think a rope can be modelled as an axis-aligned rectangle.

Gunroar:Cannon() wrote: Mon Mar 15, 2021 7:57 pm That's why I found it hard to use the normal algorithms I already found(plus its for top down use, so no gravity)...heheh.
So with this said any new ideas, or can it still be done with the other ropes?
Maybe a drawing will help understanding what you want. From your description, this is the picture that comes to my mind:
Boxes-with-rope.png
Boxes-with-rope.png (488 Bytes) Viewed 5449 times
where the boxes are always axis-aligned.

Re: Fast Rope Physics for bump.lua?

Posted: Tue Mar 16, 2021 5:23 pm
by Gunroar:Cannon()
pgimeno wrote: Tue Mar 16, 2021 1:53 pm
Maybe a drawing will help understanding what you want. From your description, this is the picture that comes to my mind:

Boxes with rope

where the boxes are always axis-aligned.
Yeah! Exactly like that. I didn't want the rope to be in the bump world, just to manipulate the ones it's attached to, and to be drawn. So any idea how to do it?