Obi Official Forum
Help Rope physics unstable - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html)
+--- Thread: Help Rope physics unstable (/thread-2379.html)



Rope physics unstable - earagon088 - 23-07-2020

Hello,

I've been trying to make a grapple gun with physics that are intuitive and at least somewhat realistic. I found your rope tech demo and figured it would be exactly what i need, however, i've been having trouble getting it to behave the way i want to, and have even had a few instances of it launching rigid bodies several orders of magnitude away from the game space.

So to start off, my basic set up was a rope connected to a rigid body and a nonRigidBody collider, i have a ObiRopeCurser set to 0,0,true IIRC and a script that runs Cursor.changeLength(rope.restLength +/- K*time.deltaTime) dependent on the player input. After a little bit of trouble shooting i got the correct attachment components and got a basic pendulum working. However the rope was extremely bouncy and stretchy, furthermore pressing the inputs seems to cause the rope to clump up near the beginning before the solver can find a solution where they're better spread out, but in doing so it will add a lot of kinetic energy to the rope, and cause the pendulum to flail about in a completely unstable fashion. Trying to reel the rope in has a different effect, it will make a ton of tension where the rope particles are being eaten, which seems to build up energy for a moment, until it reaches the other side of the rope where the rigid body is, in which time it will launch the rigidbody at an high speeds towards where the rope cursor is. Even if i just tap the reel in key, it will barely change the rope length, but the rigid body will still get launched.

At this point i remembered the tether component from the pendulum video, and how easy, intuitive, and just overall effective it was at achieving its purpose, but in looking for a way to implement it, i found that its interface has changed massively. All of the previous options replaces with a standardized few. Ive been playing around with it for awhile now, but with the few options provided in the solvers constraint menu i wasn't able to make any noticable change in its stiffness. i've tried a host of other options including increasing the rope thickness, changing the materials/template values, disabling/tweaking the other constraints in a massive variety of ways, increasing the number of substeps & enabling the unity physics substep option, increasing dampening, bend/stretch settings in the rope instance, changing where i put the rope cursor, and i've honestly no idea where to go from here.

Ive seen here on the forums its often recommended to increase the iterations (for the tether constraint) and substep count, but increasing the iterations doesn't seem to have any noticeable effect, and enabling the unity physics substeps and increasing the substep count will change the phsyics of the world in a way that makes it unusable (character jumps significantly higher, walk speed massively decreased, etc). Also it crashed 3 different times last night, i'd happily provide the crash reports if i can access them. But for right now, i'm looking into other options. I would love to use your ropes the way they're shown in your videos, i bet they would make a fantastic harpoon/tether grapple gun, but as of yet, i'm not able to recreate what i've seen.

An album of some short 30 second videos of my setup: https://imgur.com/a/z4aaDqs


RE: Rope physics unstable - josemendez - 23-07-2020

(23-07-2020, 10:56 AM)earagon088 Wrote: Hello,

I've been trying to make a grapple gun with physics that are intuitive and at least somewhat realistic. I found your rope tech demo and figured it would be exactly what i need, however, i've been having trouble getting it to behave the way i want to, and have even had a few instances of it launching rigid bodies several orders of magnitude away from the game space.

So to start off, my basic set up was a rope connected to a rigid body and a nonRigidBody collider, i have a ObiRopeCurser set to 0,0,true IIRC and a script that runs Cursor.changeLength(rope.restLength +/- K*time.deltaTime) dependent on the player input. After a little bit of trouble shooting i got the correct attachment components and got a basic pendulum working. However the rope was extremely bouncy and stretchy, furthermore pressing the inputs seems to cause the rope to clump up near the beginning before the solver can find a solution where they're better spread out, but in doing so it will add a lot of kinetic energy to the rope, and cause the pendulum to flail about in a completely unstable fashion. Trying to reel the rope in has a different effect, it will make a ton of tension where the rope particles are being eaten, which seems to build up energy for a moment, until it reaches the other side of the rope where the rigid body is, in which time it will launch the rigidbody at an high speeds towards where the rope cursor is. Even if i just tap the reel in key, it will barely change the rope length, but the rigid body will still get launched.

At this point i remembered the tether component from the pendulum video, and how easy, intuitive, and just overall effective it was at achieving its purpose, but in looking for a way to implement it, i found that its interface has changed massively. All of the previous options replaces with a standardized few. Ive been playing around with it for awhile now, but with the few options provided in the solvers constraint menu i wasn't able to make any noticable change in its stiffness. i've tried a host of other options including increasing the rope thickness, changing the materials/template values, disabling/tweaking the other constraints in a massive variety of ways, increasing the number of substeps & enabling the unity physics substep option, increasing dampening, bend/stretch settings in the rope instance, changing where i put the rope cursor, and i've honestly no idea where to go from here.

Ive seen here on the forums its often recommended to increase the iterations (for the tether constraint) and substep count, but increasing the iterations doesn't seem to have any noticeable effect, and enabling the unity physics substeps and increasing the substep count will change the phsyics of the world in a way that makes it unusable (character jumps significantly higher, walk speed massively decreased, etc). Also it crashed 3 different times last night, i'd happily provide the crash reports if i can access them. But for right now, i'm looking into other options. I would love to use your ropes the way they're shown in your videos, i bet they would make a fantastic harpoon/tether grapple gun, but as of yet, i'm not able to recreate what i've seen.

An album of some short 30 second videos of my setup: https://imgur.com/a/z4aaDqs

Hi,

Most of your stability issues seem to be caused by the attachment: you're attaching the rope inside of a collider, while collisions are enabled. This will create an energy feedback loop in the rope causing all sorts of stability issues, because you're essentially imposing two constraints that can't be met simultaneously: stay pinned inside the collider, but also stay outside of it. This situation is described in the last section of this manual page, along with the solution:
http://obi.virtualmethodstudio.com/tutorials/pinconstraints.html

Regarding stiffness, using more substeps is guaranteed to improve convergence, thus reducing stretching. With 5-6 substeps you should get practically inextensible rope.

Quote:Ive seen here on the forums its often recommended to increase the iterations (for the tether constraint) and substep count, but increasing the iterations doesn't seem to have any noticeable effect

Not tether constraints, but distance constraints. Tethers aren't used in rope so changing their iteration count won't have any effect whatsoever. Check this manual page, it describes in detail how the engine works, and how iterations/substeps affect the simulation quality:
http://obi.virtualmethodstudio.com/tutorials/convergence.html

Quote:and enabling the unity physics substeps and increasing the substep count will change the phsyics of the world in a way that makes it unusable (character jumps significantly higher, walk speed massively decreased, etc).

If your game behaves differently when using a different timestep, it means you're not taking the timestep into account at all. Things that happen in FixedUpdate() should be multiplied by Time.fixedDeltaTime, etc.


RE: Rope physics unstable - earagon088 - 03-08-2020

(23-07-2020, 12:23 PM)josemendez Wrote: Hi,

Most of your stability issues seem to be caused by the attachment: you're attaching the rope inside of a collider, while collisions are enabled. This will create an energy feedback loop in the rope causing all sorts of stability issues, because you're essentially imposing two constraints that can't be met simultaneously: stay pinned inside the collider, but also stay outside of it. This situation is described in the last section of this manual page, along with the solution:
http://obi.virtualmethodstudio.com/tutorials/pinconstraints.html

Regarding stiffness, using more substeps is guaranteed to improve convergence, thus reducing stretching. With 5-6 substeps you should get practically inextensible rope.


Not tether constraints, but distance constraints. Tethers aren't used in rope so changing their iteration count won't have any effect whatsoever. Check this manual page, it describes in detail how the engine works, and how iterations/substeps affect the simulation quality:
http://obi.virtualmethodstudio.com/tutorials/convergence.html


If your game behaves differently when using a different timestep, it means you're not taking the timestep into account at all. Things that happen in FixedUpdate()  should be multiplied by Time.fixedDeltaTime, etc.

Hello

The inter collider attachment issue was one i believe i trouble shot and solved before i made this post, so i don't believe any of the jerkiness came from that, i believe its that the ropes equivalent of mass is too high because increasing the mass of the pendulum helps to mitigate the instability that adding rope length causes. However, i don't think this is much of an issue because i don't imagine it would be very hard to figure out how to change, instead, i would like to focus on this:

Quote:Tethers aren't used in rope


This is simply not consistent with what i've read and watched, here's a quote from the very manual you linked me, which i read before i even made this thread:

(Tether constraints)

Quote:These constraints are used to [b]reduce stretching of cloth and ropes[/b], when increasing the amount of distance constraint iterations would be too expensive. Generally 1-4 iterations are enough for tether constraints.

This is my main problem with the situation, because a major selling point for me was the tether component used on a rope in one of the videos from what i believe is your official channel, this video right here: https://www.youtube.com/watch?v=fTqSZgNwGgI

At the 6:25 mark the tutorial guide demonstrates the exact same problem i'm having right how, and at 6:41 he solves it by clicking on this button labeled "generate tether", a button which seems to have since been taken out. Increasing the substep count in the obi solver does help the problem, but even putting the substep count at 10 , 20 or 40, well beyond the point it starts to effect my performance, with any combination of high/low iteration count and relaxation, the problem still resides. When any significant ammount of tension is applied the rope stretches, and then elastic whips my object around.

I don't believe distance constraints are the solution to my problem, i believe they are the source, and i believe that your tether's were designed to fix exactly this problem;

A few side notes: 

1) It seems that in my player gravity script i did indeed forget to scale it by time.fixedDeltaTime, so thanks for helping me find that. 
2) Every now and then, my console throws a "Look rotation viewing vector is zero" at me, it doesn't seem to cause any problems, its not even classified as a warning or error in the unity console, its just a regular message like that of Debug.Log(), but it only does this when i'm using an ObiRope;
3) I also, every now and then, when increasing my rope length, get a IndexOutOfRangeException sub scripted with "Obi.ObiActor.SwapWithFirstInactiveParticle (System.Int32 actorIndex)(at assets/Obi/Script/Common/Actors/ObiActor.cs:420) error, again it doesn't cause any immediately noticeable problems, is it something i should be concerned about?


RE: Rope physics unstable - josemendez - 03-08-2020

Tethers were used in ropes up to Obi 5.0. With the inclusion of substepping (from this article: http://mmacklin.com/smallsteps.pdf), we found they were no longer needed in most cases -as substepping boosts convergence enormously- so we removed them. Tethers had a plethora of associated issues that made their use cases quite limited:

- You can't change rope length, or cut it, while using tethers.
- You can't dynamically attach/detach particles while using tethers.
- They only work in pendulum-like cases, in which the object attached to the rope and the anchored point of the rope lie in a straight line. Pulleys and similar systems don't benefit from tethers.
- Sections of the rope in-between tethers would have too much slack if not enough distance constraint iterations were used.

The mention of ropes in the manual is a leftover from the 4.X manual, so it should not be there. Removing it.

Quote:I don't believe distance constraints are the solution to my problem, i believe they are the source, and i believe that your tether's were designed to fix exactly this problem;

Distance constraints are the basic building blocks of ropes. Without them , the rope would lose all structural integrity and just collapse into a point. Increasing the amount of distance constraint iterations will solve your problem, however using more substeps is even more effective.

Tethers rely on a pre-process of the rope, so you can't have topological changes of any kind while using them. This makes them really limited as I just explained. The problem they used to solve is no longer a problem when using a few substeps. If this is not possible/ideal in your case, hearing more about what you're trying to accomplish will allow me to help further.

Quote:Every now and then, my console throws a "Look rotation viewing vector is zero" at me, it doesn't seem to cause any problems, its not even classified as a warning or error in the unity console, its just a regular message like that of Debug.Log(), but it only does this when i'm using an ObiRope;

This message is usually thrown by a quaternion that has been made to look in a direction that's the zero vector. Quaternions are not used in ropes simulation as rope particles do not have any orientation. Are you using rods instead by any chance?


Quote:I also, every now and then, when increasing my rope length, get a IndexOutOfRangeException sub scripted with "Obi.ObiActor.SwapWithFirstInactiveParticle (System.Int32 actorIndex)(at assets/Obi/Script/Common/Actors/ObiActor.cs:420) error, again it doesn't cause any immediately noticeable problems, is it something i should be concerned about?

This is something to be concerned about, as any out of bounds array is considered a bug. Can you give steps to reproduce this?


RE: Rope physics unstable - earagon088 - 03-08-2020

Wow that was a fast response, i'm not at my desktop right now so i can't work with unity ATM but:


Quote:Tethers rely on a pre-process of the rope, so you can't have topological changes of any kind while using them.




I see, unfortunate. That does kinda nullify all the use i thought it would have in this situation, i assumed the tether would have its limits in situations where the rope was under tension but the first and last particle were close enough to where a tether wouldn't have effect, such as being bent around a corner. I was hopeful that there would be a way to dynamically add tether effects to mid points of the particles to help mitigate this, but yea, a tether doesn't seem to be what i'm looking for.

Quote:Are you using rods instead by any chance?


Im fairly certain i have the right object, i did the basic gameObject, create, Obi, ObiRope, (or whatever the path is) which made me an ObiSolver with a ObiRope child. I haven't tried rods yet.

Quote:Can you give steps to reproduce this?


I can reproduce it but it doesn't really take much in terms of steps, i just make a rope pinned to a few rigid bodies, slap on my rope script (basically just ObiRopeCurser.changeLength(restLength + K * deltaTime)) and it will pop up once every several minutes playing with the rope. I probably should have mentioned this earlier but when i first imported your asset files or whatever they're called, unity hit me with some sort of "API Obsolete" pop up, there was a bunch of warnings in the console but i accidentally cleared them all away before i could read them and they never showed up again, i figured sense they were warnings not errors it shouldn't be a problem but now i'm thinking this, the lookVectorZero, rope instability, and memory access violations might all be related. I believe i can reproduce this if i delete and reimport your rope assets, should i try?