Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[SOLVED] Creating a custom Offset Point for a weld that holds two already-existing parts together?

Asked by
Uglypoe 557 Donator Moderation Voter
7 years ago
Edited 7 years ago

Hi! I'm trying to set up a welding system that welds two existing parts together in their current positions, but with a preset Offset Point that I manually create. The Offset Point is a Vector3 Value. I've been trying all day to figure it out, and frankly my head hurts. All I'm really looking at is the C0 and C1 values, I've got everything else working fine.

This is my what my latest attempt looks like:

NewWeld.C0 = CFrame.new(Joint.Value - P0.Position) * CFrame.Angles(math.rad(Part.Rotation.X),math.rad(Part.Rotation.Y),math.rad(Part.Rotation.Z))
NewWeld.C1 = CFrame.new(Part.Position - Joint.Value)

If anybody has any help, I'd really appreciate it. Thanks.

Edit 1: It appears that this creates the offset point in the correct position, but the initial rotations are still messed up. I want the parts to maintain their position and rotation after being welded, with the offset point being set to whatever the Vector3 Value was.

NewWeld.C0 = P0.CFrame:toObjectSpace(CFrame.new(Joint.Value)* CFrame.Angles(math.rad(Part.Rotation.X),math.rad(Part.Rotation.Y),math.rad(Part.Rotation.Z)))
NewWeld.C1 = Part.CFrame:toObjectSpace(CFrame.new(Joint.Value))

Edit 2: With some messing around, I was able to find the solution on my own. I should've realized that :toObjectSpace() would also pass through some sort of rotation on it's own. Thus, the correct way to do it was:

NewWeld.C0 = P0.CFrame:toObjectSpace(CFrame.new(Joint.Value))
NewWeld.C1 = Part.CFrame:toObjectSpace(CFrame.new(Joint.Value))

Answer this question