Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix saggy constraints #50

Open
Nebual opened this issue Aug 21, 2013 · 15 comments
Open

Fix saggy constraints #50

Nebual opened this issue Aug 21, 2013 · 15 comments

Comments

@Nebual
Copy link
Member

Nebual commented Aug 21, 2013

dude advdupe sucks because it makes saggy welds
"Saggy welds are an inevitable problem with how constraints are made. Theres nothing we can do to fix it, though > you'll get much stronger welds if you freeze your props before duping them"
ya but advdupe2 can do it
"grumbles and leaves"

-- Me, versus the unwashed masses

Okay, so advdupe2's solution was to hook into OnEntityCreated, and save the local positions of all physics objects involved in the constraint into the constraint itself. When pasting, it simply moves the physics objects to their original locations when the constraint was first made, pastes the constraint, then moves them back. It may seem a bit hacky, and its not 100% effective in all cases, but its a whole lot better than what we do now with regards to constraints.

I don't know if TB can copyright the basic idea of the above paragraph, as obviously copypasting his exact code isn't applicable, but we need to do something like it.

Advdupe2:
Save initial constraint positions line 18
Hook into OnEntityCreated to call the above function line 72
Inside PasteConstraint, before running the factory function, move ents into place line 519
Inside PasteConstraint, after running factory function line 569

@AbigailBuccaneer
Copy link
Contributor

What's the fundamental issue causing saggy constraints - are things being physically simulated before the constraints are made and so they move due to gravity? Is the constraint solver moving things when some but not all of the constraints have been added?

Would it work to weld everything to a gmod_anchor before applying the actual constraints? It'd be a lot less code.

@Divran
Copy link
Contributor

Divran commented Aug 21, 2013

If you take 10 props in a line and weld them one to the other, and then lift the whole thing up with the physgun, you're going to get massive sags.

If you then dupe this saggy line of props with duplicator or adv duplicator, and paste it, the constraints will be created while the props are in these weird positions. This means that if you now lift it up again, it'll have as much leeway to sag as earlier, meaning they'll sag even more.

This is the cause of saggy constraints and this is what adv dupe 2 fixes by memorizing the original positions of everything. (This problem also applies to less obvious situations)

@AbigailBuccaneer
Copy link
Contributor

Ah, we lose all the 'potential energy' in the constraints.

I bet we could override constraint.AddConstraintTable to add relative position data to every constraint instead of hooking OnEntityCreated. Less code, and we store the info in the constraints themselves.

(We could then totally get that into vanilla GMod, and make Garrydupe awesome.)

@Nebual
Copy link
Member Author

Nebual commented Aug 21, 2013

I bet we could override constraint.AddConstraintTable

I worry that the later use of Constraint:SetTable(small ctable) would override anything we try to store in the constraints themselves. Something like that might work though yes.

@Anticept
Copy link
Member

You know what is funny about saggy constraints?

A long time ago, the work around was to rope everything. After pasting and removing the ropes, there were no sags, no matter how many dupes you made.

I still do not know why that worked. But it did.

@Nebual
Copy link
Member Author

Nebual commented Aug 22, 2013

I'm not sure I fully comprehend the problem anymore.

I've spent hours fiddling at it, I can get it so 5 generations later, a pasted slinky (40 stacked plates) looks awful (some gaps are way larger), but upon freezing each component individually it looks perfect again. So the welds are being made in the right place.... they just sag.

@Anticept
Copy link
Member

I wonder... Try doing that in 0 gravity. I wonder if duplicator is also saving the gravity forces acting on the contraptions and it's cumulating.

@Jack37
Copy link
Member

Jack37 commented Aug 22, 2013

It's the same with 0 gravity.
No matter if it's frozen before duping or no, the welds will be saggy after pasting. I stacked 10 props (frozen, collided and not welded), then welded them together and duped. Then spawned on original position, and after undrozing both of them, those pasted had some really saggy welds on some places.

@Anticept
Copy link
Member

Again, does duping with ropes still work?

@Jack37
Copy link
Member

Jack37 commented Aug 24, 2013

Again, does duping with ropes still work?

Works perfectly 👍

@Anticept
Copy link
Member

So, now we need to dig in and understand how ropes interact with the physics of duping.

What happens if you change the weight of duped objects? If you were to zero out the weight on dupe, then after paste it puts the weight back, rinse and repeat, does it still cause problems then?

@Jack37
Copy link
Member

Jack37 commented Aug 24, 2013

No the weight does not work, and um I tried the ropes again and it somehow did not work this time, I'm sure I did everything in the same way as before, it'll be better if someone else confirm this too.

@Anticept
Copy link
Member

You have to put the ropes on, dupe, paste, then remove the ropes.

@TBbadmofo
Copy link

Just for further research in bettering this issue. I didn't have any benefit with the ropes, but with out replicating positions when it was constrained, it will still degrade. If you constrained the 10 props, froze 1 end and curved the other end around and froze it, when you duplicate it, it will be replicated very distorted. Since AD2 saves positions when constrained, it will not be distorted after replication. So, without saving positions if you try and lock and freeze your 100 prop contraption it may move slightly over time of copying and wouldn't perform the same; and also have to do the hassle of locking and freezing. It could probably go a step further and try and spawn the entities and constraints in in the order they were spawned into the game to try and get closer to matching their stepping calculations in the physics engine from the original creation.

@thegrb93
Copy link
Contributor

Yea, if constraints are ordered randomly then the contraption will spawn with random constraint systems and won't be a single solid constraint system. Advdupe2 orders them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants