How do you position a model to a character?

I’m unable to get the models to behave correctly on the character.

I’m switching between WeldContrains and Motor6d. Neither of them bring acceptable results. Welding a model to a character should be a trivial thing to achieve, but it feels impossible to me.

Let’s go over the behavior with using WeldConstraints;

  • Pros
  1. It positions the parts with their original position, which means that the parts within the model are positioned correctly.
  • Cons
  1. The parts welded to the arms move the opposite way of the character’s movement.

  2. The parts don’t follow the character precisely enough, causing the HumanoidRootPart and arms to glitch through the parts welded to them.

Image of result:
image

Script method:

			local function addConstraints(model,character,targetPart)

				for index,part in pairs(model:GetDescendants()) do
					
					if part:IsA("BasePart") then

						local constraint = Instance.new("WeldConstraint")
						constraint.Parent = part
						constraint.Part0 = part
						
						if targetPart.Name == "Head" then
							
							constraint.Part1 = targetPart
							
						elseif targetPart.Name == "HumanoidRootPart" then
							
							local left = model:FindFirstChild("Left")
							local middle = model:FindFirstChild("Middle")
							local right = model:FindFirstChild("Right")
							
							if part:IsDescendantOf(left) then
								
								constraint.Part1 = character:FindFirstChild("Left Arm")
								
							elseif part:IsDescendantOf(middle) then
								
								constraint.Part1 = targetPart
								
							elseif part:IsDescendantOf(right) then
								
								constraint.Part1 = character:FindFirstChild("Right Arm")
								
							end
							
						end

					end
					
				end

			end
			
			modelToEquip:PivotTo(targetPart.CFrame)
			addConstraints(modelToEquip,character,targetPart)

Now for the behavior when using Motor6D;

  • Pros
  1. The parts welded to the arms are now moving in the correct direction.
  • Cons
  1. It does not position the parts at their original position, which means that the parts within the model are positioned at the targetPart (HumanoidRootPart or Head). Applying an offset seems to bring random results.

  2. The parts don’t follow the character precisely enough, once again causing glitching, however it is worth mentioning that it glitches less than a WeldContraint.

Image of result:
image

Script method (important to note that I have tried most of the things on devforum, inversed offsets and so on. Of course if you have a code suggestion, I will test it. This is simply to inform that I have tried my best to find any sense in creating a proper offset.):

			local function addConstraints(model,character,targetPart)

				for index,part in pairs(model:GetDescendants()) do
					
					if part:IsA("BasePart") then

						local constraint = Instance.new("Motor6D")
						constraint.Parent = part
						constraint.Part0 = part
						
						if targetPart.Name == "Head" then
							
							constraint.Part1 = targetPart
							
						elseif targetPart.Name == "HumanoidRootPart" then
							
							local left = model:FindFirstChild("Left")
							local middle = model:FindFirstChild("Middle")
							local right = model:FindFirstChild("Right")
							
							if part:IsDescendantOf(left) then
								
								constraint.Part1 = character:FindFirstChild("Left Arm")
								
							elseif part:IsDescendantOf(middle) then
								
								constraint.Part1 = targetPart
								
							elseif part:IsDescendantOf(right) then
								
								constraint.Part1 = character:FindFirstChild("Right Arm")
								
							end
							
						end
						
						constraint.C0 = ???

					end
					
				end

			end

			addConstraints(modelToEquip,character,targetPart)
			
1 Like
  1. Replace HRP with Torso.

  2. Rename on of your parts parented to the model to “mainPart” and then only add contraints on that. This way positions won’t stack.

  3. Use Motor6D, and then capture the positions of the model to put onto the constraint0.

  4. Make 2 versions of models if it has multiple limbs. 1 for visual and 1 for equipping the model. For my character it’s about 1.5 studs for arm space (and -1.5 for the opposite arm). So your equip model will have 0~, and your model for visual rendering like a viewport frame will be about 1.5 studs (you will see the studs when you build the actual model).

local function addConstraints(model,character,targetPart)

				for index,part in pairs(model:GetDescendants()) do

					if part:IsA("BasePart") and part.Name == "mainPart" then
						
						local xOffset = -part.Position.X
						local yOffset = -part.Position.Y
						local zOffset = -part.Position.Z
						--print(modelToEquip.Name,xOffset,yOffset,zOffset)

						local constraint = Instance.new("Motor6D")
						constraint.Parent = part
						constraint.Part0 = part

						if targetPart.Name == "Head" then

							constraint.Part1 = targetPart

						elseif targetPart.Name == "Torso" then

							local left = model:FindFirstChild("Left")
							local middle = model:FindFirstChild("Middle")
							local right = model:FindFirstChild("Right")

							if part:IsDescendantOf(left) then

								constraint.Part1 = character:FindFirstChild("Left Arm")

							elseif part:IsDescendantOf(middle) then

								constraint.Part1 = targetPart

							elseif part:IsDescendantOf(right) then

								constraint.Part1 = character:FindFirstChild("Right Arm")

							end

						end

						constraint.C0 = CFrame.new(xOffset,yOffset,zOffset)

					end

				end

			end
			
			local targetPart = nil
			
			if validNamesHead[equipSlot] then
				
				targetPart = character:FindFirstChild("Head")
				
			elseif validNamesHRP[equipSlot] then
				
				targetPart = character:FindFirstChild("Torso")
				
			end
			
			addConstraints(modelToEquip,character,targetPart)

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