Fast Rope Physics for bump.lua?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
MrFariator
Party member
Posts: 509
Joined: Wed Oct 05, 2016 11:53 am

Re: Fast Rope Physics for bump.lua?

Post by MrFariator »

You could use bump's querySegment or querySegmentWithCoords functions to check the rope's path from its origin to where it's supposed to end up. If any collisions happen between the origin and goal, draw a line between the origin and the appropriate corner, and then draw the remainder of the rope's length from the said corner to the goal. Kind of like line-of-sight that turns around at corners it encounters along the way. With some simple trigonometry you can keep the length of the rope constant, just keep track of the overall length as you split the rope into segments.

This should be fairly straight forward for shorter ropes that don't ever get the chance to wrap around multiple corners, but should be possible to extend to longer lengths with some additional consideration.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Fast Rope Physics for bump.lua?

Post by pgimeno »

For a general case this needs pretty much a custom physics engine, and probably dropping bump.lua, but since you (Gunroar:Cannon()) haven't described anything about the objects, we have no info on what can be simplified and what can't. Even with love.physics, handling this can be difficult in a general case. This particular case could easily be resolved with a PulleyJoint, but if you want to allow the bodies to move freely, it should probably be a RopeJoint instead and converted to a PulleyJoint when the rope hits a corner. Or to build the rope out of collidable segments joined by RevoluteJoint's. Not trivial in either case.

For special cases, when your objects can only move in certain ways, simplifications could perhaps be made, but we don't know.

MrFariator wrote: Tue Mar 16, 2021 5:43 pmWith some simple trigonometry you can keep the length of the rope constant,
Sorry for the pickiness, but that doesn't need trigonometry, just vector math. I point it out because I see too many people using trigonometry where none is necessary, bloating and slowing down their code.
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: Fast Rope Physics for bump.lua?

Post by Gunroar:Cannon() »

MrFariator's way seems close to the solution...
pgimeno wrote: Tue Mar 16, 2021 7:33 pm For a general case this needs pretty much a custom physics engine, and probably dropping bump.lua, but since you (Gunroar:Cannon()) haven't described anything about the objects, we have no info on what can be simplified and what can't. Even with love.physics, handling this can be difficult in a general case. This particular case could easily be resolved with a PulleyJoint, but if you want to allow the bodies to move freely, it should probably be a RopeJoint instead and converted to a PulleyJoint when the rope hits a corner. Or to build the rope out of collidable segments joined by RevoluteJoint's. Not trivial in either case.

For special cases, when your objects can only move in certain ways, simplifications could perhaps be made, but we don't know.

MrFariator wrote: Tue Mar 16, 2021 5:43 pmWith some simple trigonometry you can keep the length of the rope constant,
Sorry for the pickiness, but that doesn't need trigonometry, just vector math. I point it out because I see too many people using trigonometry where none is necessary, bloating and slowing down their code.
Thnx alot, but as I was thinking of MrFariator's then I saw yout trigonometry thing saying it slows down stuff, I paused, since I need it to be fast. I don't really need the rope to bend in any circular type of way, just straight lines, and it only bends when it's by a corner, like you(p.gimeno) showed(just incase).
The basic of an entity that will be used by that rope is in the testcase I posted by bases/Entity if you need the description to make an example. But I'll put in a short overview:
All Entities basically have:
int vx, vy - velocity
int x,y - position
int w,h - size
Though I'm not sure that alone should help, so the whole thing is in the testcase.
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Fast Rope Physics for bump.lua?

Post by pgimeno »

Gunroar:Cannon() wrote: Tue Mar 16, 2021 11:30 pm Thnx alot, but as I was thinking of MrFariator's then I saw yout trigonometry thing saying it slows down stuff, I paused, since I need it to be fast. I don't really need the rope to bend in any circular type of way, just straight lines, and it only bends when it's by a corner, like you(p.gimeno) showed(just incase).
Many people, when confronted with a problem involving circles, think trigonometry, but that's wrong. Trigonometry is more probably involved when dealing with angles, and in this case there are no angles involved. You can even draw a circle without using any trigonometry, just search for Bresenham's circle.

Gunroar:Cannon() wrote: Tue Mar 16, 2021 11:30 pm The basic of an entity that will be used by that rope is in the testcase I posted by bases/Entity if you need the description to make an example. But I'll put in a short overview:
All Entities basically have:
int vx, vy - velocity
int x,y - position
int w,h - size
Though I'm not sure that alone should help, so the whole thing is in the testcase.
What testcase? The one from the bump thread? I don't see any ropes there, so I don't know how they are supposed to behave in the presence of a rope, or what constitutes a corner where the rope can collide.

To say that they have a position, a velocity and a size is to say that they are widely general, and the complications I mentioned apply. Having an idea of what they represent would help knowing what limitations in movement they may have.
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: Fast Rope Physics for bump.lua?

Post by Gunroar:Cannon() »

pgimeno wrote: Wed Mar 17, 2021 12:02 am What testcase?
me
me
download.jpg (4.23 KiB) Viewed 3657 times
:rofl: :rofl: :rofl: :rofl: I was sleepy, sorry, I confused the to threads, I commnt on thm the same time so(correction: I am sleepy) :rofl: . Yes it is that one download/file.php?id=19320&sid=bb3a6fe0 ... a756b4a6d5,
pgimeno wrote: Wed Mar 17, 2021 12:02 am The one from the bump thread? I don't see any ropes there, so I don't know how they are supposed to behave in the presence of a rope, or what constitutes a corner where the rope can collide..
And testcase is what I just called it there for that topic, I don't really have a solid clue in making this, just the idea, that's why I asked in general.Sorry for the trouble and thnx for still helping.
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
MrFariator
Party member
Posts: 509
Joined: Wed Oct 05, 2016 11:53 am

Re: Fast Rope Physics for bump.lua?

Post by MrFariator »

pgimeno is asking about how should the ropes ultimately behave, and your existing code (the test case) only gives us some vague entity representation that a rope should in your opinion have. What does it mean for the rope to have width and height, or even velocity? Do you actually want ropes to have a defined thickness that affects collisions?

In your opening post you mentioned the ropes should be realistic, then said they should be affected by the catenary effect, and only then specified the top-down perspective. Don't make us guess as to what you want, and tell us how they should work, in what kind of situations, and if there are any constraints involved (eq. can an object with a rope can only be pulled into one direction, how long should the ropes be, are the objects that have a rope attached on a grid or are they arbitrarily placed, etc). Depending on what you want, the code may either become more or less complicated.
pgimeno wrote: Tue Mar 16, 2021 7:33 pm
MrFariator wrote: Tue Mar 16, 2021 5:43 pmWith some simple trigonometry you can keep the length of the rope constant,
Sorry for the pickiness, but that doesn't need trigonometry, just vector math. I point it out because I see too many people using trigonometry where none is necessary, bloating and slowing down their code.
Fair point, mostly a slip of the tongue on my part since generally I've used trigonometry a whole ton more than vectors, outside programming anyway.
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: Fast Rope Physics for bump.lua?

Post by Gunroar:Cannon() »

MrFariator wrote: Wed Mar 17, 2021 7:38 am pgimeno is asking about how should the ropes ultimately behave, and your existing code (the test case) only gives us some vague entity representation that a rope should in your opinion have. What does it mean for the rope to have width and height, or even velocity? Do you actually want ropes to have a defined thickness that affects collisions?

In your opening post you mentioned the ropes should be realistic, then said they should be affected by the catenary effect, and only then specified the top-down perspective. Don't make us guess as to what you want, and tell us how they should work, in what kind of situations, and if there are any constraints involved (eq. can an object with a rope can only be pulled into one direction, how long should the ropes be, are the objects that have a rope attached on a grid or are they arbitrarily placed, etc). Depending on what you want, the code may either become more or less complicated.
Oh, I'm sorry, I see now. The thing I explained was entities which is what the rope should be affecting, the rope itself should not be an entity(and should not be added to the bump world). Maybe a class that attaches to two entities then just changes the position of the slower object it's attached to if the faster object moves, and that can be drawn(graphics).

I see my contradiction in asking it to be realistic, what I meant was not the rope itself, but the forces applied to the entities by each other due to the tug of the rope.

The ropes should be attached to an entity at any point specified.
I don't need the rope to grow/stretch, if that makes it more complicated. Just want it to bend around corners when it meets one(maybe could be checked by seeing if the entities it's attached to are separated by a wall?).
The rope maybe able to break, if it lasts to long, not really from stretching, but this is game logic and not needed.
The two entities should never have a distance longer than the rope but should pull each other depending on the one with a bigger velocity(and weight?).

Does this clear it up?
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Fast Rope Physics for bump.lua?

Post by pgimeno »

Gunroar:Cannon() wrote: Wed Mar 17, 2021 11:50 am The two entities should never have a distance longer than the rope but should pull each other depending on the one with a bigger velocity(and weight?).
The rope in T2R behaves like this. You can feel the tug when the rope tightens, for example.

What it doesn't support is bending around corners; I already discussed why that makes things harder.

Also, I'm still wondering about the scenario where that would work fine with AABBs.
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: Fast Rope Physics for bump.lua?

Post by Gunroar:Cannon() »

pgimeno wrote: Thu Mar 18, 2021 11:11 am
Gunroar:Cannon() wrote: Wed Mar 17, 2021 11:50 am The two entities should never have a distance longer than the rope but should pull each other depending on the one with a bigger velocity(and weight?).
The rope in T2R behaves like this. You can feel the tug when the rope tightens, for example.

What it doesn't support is bending around corners; I already discussed why that makes things harder.

Also, I'm still wondering about the scenario where that would work fine with AABBs.
If it makes things to complicated I could just make bending around corners not possible and cause the rope to "break" when that happens. Does it/canip it be made to work with my entity class?
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Fast Rope Physics for bump.lua?

Post by pgimeno »

Probably, I haven't checked in much detail. I designed it with Verlet integration in mind, so if you don't use it YMMV.
Post Reply

Who is online

Users browsing this forum: Google [Bot], veethree and 40 guests