CFrame and Weld not working properly?

Hello, so recently I’ve began working on a delivering system for one of my games, It’s going great but I’m running into an issue that I cannot seem to fix AT ALL.

So how this works is a player enters a zone and receives a box, they have to deliver it, the issue is the the box isn’t CFraming properly, I want the box’s CFrame to be set to Character.UpperTorso.BodyFrontAttachment.CFrame and I’ve tried setting it but this is what I get as a result:

The way I would like it to turn out is something similar to this:

Here is the code behind it:


	local animator : Animator = self.character.Humanoid.Animator
	self.holdingBoxAnimation = Instance.new('Animation')	
	self.holdingBoxAnimation.AnimationId = deliveringData.holdingBoxAnimation
	
	local preloadList = {
		self.holdingBoxAnimation
	}
	
	contentProviderService:PreloadAsync(preloadList)
	
	animator:LoadAnimation(self.holdingBoxAnimation):Play()
	
	self.box = gameResources.DeliveringJob.CardboardBox:Clone()
	self.box.Parent = self.character.RightHand
	
	local weldConstraint = Instance.new('Weld')
	weldConstraint.Parent = self.character.RightHand
	weldConstraint.Part0 = self.box
	weldConstraint.Part1 =	self.character.RightHand
	weldConstraint.C0 = weldConstraint.Part0.CFrame
	weldConstraint.C1 = self.character.UpperTorso.BodyFrontAttachment.CFrame


As you can probably tell, this isn’t the full code but rather the part that is running the weld, if you need to view more code let me know.

2 Likes

This is wrong because C0 and C1 are CFrame relative to Part0 and Part1’ CFrames respectively. You have given them World CFrames instead. Most likely C0 can be left as identity and C1 should be some offset relative to the hrp. You don’t need an attachment in this case, that is for the new Constraints.

	weldConstraint.C0 = CFrame.new()
	weldConstraint.C1 = CFrame.new(Vector3.new(1, 2, 3)) --any offset you desire

These CFrames together always satisfy the following:

Part0.CFrame * C0 = Part1.CFrame * C1

3 Likes

Thanks.

I don’t believe it is possible to attach a part to the upper torso, C0 and C1 are both relative to the part so if you set the C0 to the part and the C1 to the upper torso’s attachment the part will not attach.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.