PGS Weld-like constraint with Attachment compatibility

User Story:

As a developer, it is not easy to dynamically swap out welded components on a model. WeldConstraints are close, but don’t suit all of my needs because they don’t support attachments.

Use Cases:

  • Attachments on cannon slots for a boat and on the bottom of cannons to dynamically swap out various models of cannons and attach them with some sort of weld constraint
  • Attachments on turret slots for planes and on the mounting points of turrets for similar reasons
  • Attachment points of windows/window frame on pieces of a wall tileset so users can swap out windows in their walls
  • Attachment points on a farm plot model and on crops so they can be dynamically added to the plot

Benefits of Resolution:

If ROBLOX is able to address this issue, it will be a lot easier for me to switch out swappable components on models. My current options are to use attachments or a settings ModuleScript to store offset, and then connect with a standard weld.

Current:

oldTurret:Destroy() --also uncontrollably deletes weld wherever it's parented```
local weld = Instance.new("Weld")
weld.Part0 = slotAttachment.Parent
weld.Part1 = newTurretAttachment.Parent
weld.C0 = slotAttachment.CFrame
weld.C1 = newTurretAttachment.CFrame
weld.Parent = slotAttachment
newTurret.Parent = ship

Proposed:

oldTurret:Destroy()
weldConstraint.Attachment1 = newTurretAttachment
newTurret.Parent = ship

As you can see, it's a lot easier to swap out turrets because I don't have to rebuild the weld each time, and I don't need to manually set the offsets of the constraint because attachments already do that. I'm not sure if it's more appropriate to incorporate this into WeldConstraint or make it its own class.
12 Likes

This is an interesting proposal. We have the WeldConstraint which constraint two parts in their initial relative locations. This is much simpler than adding another layer of cframes (aka Attachments).

Yep, I was originally looking at WeldConstraint to see if it offered this functionality. Unfortunately, these aren’t two parts I’m looking to weld based on their existing positions – I need a constraint to weld two attachments which could be anywhere in the world together.

Like you said though, using relative location instead of attachments is easier to use, so that’s why I mentioned I wasn’t sure if it was appropriate to integrate this into WeldConstraints (e.g. JoinBehavior = Part or Attachment w/ Part0/Part1 or Attachment0/Attachment1) or create a whole new class.

1 Like

Yes you are right you’ll need a little script to do that. What you can do is place the two parts at the world positions of the attachments, and the use WeldConstraint. In pseudo code:
part0.CFrame = part0.CFrame * part0.Attachment.CFrame
part1.CFrame = part1.CFrame * part1.Attachment.CFrame
create WeldConstraint between part0 and part1

That’s pretty much what I’m doing right now with Welds, so WeldConstraints aren’t really an improvement for this use case.

I wonder if you need a simulated “Rigid Constraint” that will enforce the relative locations of its Attachments using the physics solver. You could try this out by using a Hinge set up as a servo motor, which essentially behaves like a rigid constraint. It will move the parts for you based on the Attachment locations.

2 Likes

Agreed with @timobius. Attachment based Welds have a fundamental problems:

  • very easy to create an invalid configuration
  • the parts need to move into position that respect the attachment welds, and the motion is not physically defined

What you need is to explicitly move your parts into position for welding, the way you want. Otherwise like it was suggested, you might need a simulated rigid joint (which we don’t have at this point but a prismatic with a servo can emulate that).

2 Likes