Offcentering a weld?

  1. What do you want to achieve? Keep it simple and clear!
    I’d like to weld a part to a certain part of a players torso.
  2. What is the issue? Include screenshots / videos if possible!
    So, I made it so it actually welds it, however, the part is stuck inside the players torso, inside of being on their back. The part is a backpack.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried offcentering the weld a bit by myself, but it always ended up either not welding, or the part being welded to the player, but the part was on the other side of the baseplate. Yes, I’ve looked around the internet, but couldn’t find anything.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

This is my code so far:

local hrp = script.Parent.Parent:WaitForChild("Torso")
local main = script.Parent

local weld = Instance.new('Weld', main)
weld.Part0 = main
weld.Part1 = hrp

Any help would be greatly appreciated!

Some screenshots to help you understand:
Imgur
Imgur

3 Likes

Welds have a C0 which is a CFrame offset that you can apply.

FYI: Don’t use the second argument of Instance.new (Parent argument), you’ll learn why here:


An alternative solution to Welds would be to use the underrated Accessory system, you just have setup an Attachment in both the Accessory’s Handle and the limb you want it to attach to. Of course, Attachments have more customisable properties.

1 Like

thank you for your reply! didn’t know about the performance issues, so that’s informative. however, to offcenter a weld, would i just do like:

weld.C0 = main.CFrame
weld.C1 = hrp.CFrame * -- insert cframe that would work decently here

Are you wanting to weld two baseparts together and at the same time maintain their positions?
Just gotta make sure…

i’m trying to weld a part (the backpack) and a basepart (the players torso) together, and i want the part to be just a bit off-centered so its not inside the torso, but its on the actual back.

Alright, so you’re wanting to preserve the offset so they stay in place when you weld them? That’s at least what I understood from what you said.

To do so, you’d have to calculate the offset (by other means the offset CFrame you’d have to combine the Part0’s Cframe with to get the Part1’s current CFrame) which I would do like this:

local Part0, Part1 = TorsoHere, BackpackHere
local Weld = Instance.new("Motor6D") -- I prefer using Motor6D
Weld.C0 = Part0.CFrame:inverse() * Part1.CFrame -- This is object space. Equivalent to Part1.CFrame = Part0.CFrame * Weld.C0 if world space
Weld.Part0 = Part0
Weld.Part1 = Part1
Weld.Parent = Part0 or Part1 ?
1 Like

Hey! It surely off-centered the weld, so thank you for the solution! I just have one question, what does :inverse() do? :smile: Thank you for your answer!

Also, there’s another issue. The backpack gets offcentered A LOT more than it should, what I mean by that, is that is goes underground.

Let’s say you have a CFrame to start with, like CFrame.new(10, 35, -5). Applying the :inverse() function on this CFrame will inverse the position and orientation (remember CFrames consist of both position and orientation data) and return CFrame.new(-10, -35, 5) with this simple example.

But… how is this relevant to welding? Well, a pivot point is where the CFrame would be offset to and if for example the pivot point was set to (20, 4, 0) then any coordinate applied would be equivalent to Pivot * Offset or let’s say (Pivot) (20, 4, 0) + (6, 2, 5) (Offset) would result in (26, 6, 5) in world-space (where the pivot is always (0, 0, 0)). So, to get back to the original point, the .C0 is actually an offset, offset to the pivot (the pivot is the Part0’s coordinates).

In world-space if the Part0’s coordinates is (10, 20, 30) and the .C0 is (0, 0, 0) then the Part1’s coordinates would (in world-space) translate to (10, 20, 30) + (0, 0, 0) which is still (10, 20, 30) since the pivot is the Part0’s coordinates.

So! To get back to how this is relevant to welding. To translate the Part1’s CFrame from world-space (pivoting around (0,0,0)) to object-space (pivoting around Part0’s coordinates) you would have to inverse the Part0’s coordinates by using the :inverse() function of the CFrame to make the Part0’s coordinates into (0, 0, 0) (in world-space) and then add the Part1’s coordinates to maintain its offset.

Summary:

  1. The .C0 property of a weld is the CFrame value which is multiplied with the pivot point (Part0’s CFrame).
  2. When .C0 is CFrame.new(0, 0, 0) which it is by default, it is equivalent to Part0.CFrame in world space.
  3. Therefore we use the :inverse() function to eliminate the Part0.CFrame to achieve CFrame.new(0, 0, 0) in world-space.
  4. Then we multiply the Part1’s CFrame with the new pivot to maintain the Part1’s initial coordinates which it had in world-space.

I hope this explanation wasn’t too confusing and messy ahah. :grin:

3 Likes

thank you for you explanation! could you also explain why the other error is also happening?

Can you provide a screenshot? I think I know what you mean, though.

To prevent this, I’d weld the backpack in studio by using an r6 or r15 rig then position the backpack where I’d want it to be relevant to the torso then weld them together (in studio using the command bar) and parent the weld to the backpack then use the existing weld but just with code when the game is running change the Part0 and Part1 to the torso and the backpack so the backpack “attaches” to the torso.

Personally, I’d use a plugin like RigEdit to create the actual weld and then just have a script that sets the Part0