How to make part stay in fixed position when welded

Hello, I am trying to make it so the weldCirclePart is in a fixed position during the weld.

As you can see in the video, it is moving relative to how the primary part of the tower moves, and its going under the ground sometimes, to the side.

What I am trying to do is make it stay fixed at its position and prevent it from rotating, going under the baseplate

local HandleWeld = {}

function HandleWeld:TowerCircleWeld(tower: Model, weldCircle: Part)
	print(weldCircle.Parent)

	local weldConstraint = Instance.new("WeldConstraint")
	weldConstraint.Part0 = weldCircle
	weldConstraint.Part1 = tower.PrimaryPart
	weldConstraint.Parent = weldCircle
	
	weldCircle.Parent = tower
	weldCircle.CFrame = tower.PrimaryPart.CFrame

	local weldAttachment = weldCircle.CircleAttachment :: Attachment
	weldAttachment.WorldCFrame = tower.PrimaryPart.CFrame * CFrame.new(0, -1.5, 0)
end

return HandleWeld

WeldConstraint will connect the orientation of your tower to weldCircle
I recommend use CFrame to do the job instead

local towerCFrame = tower.CFrame

-- get the direction the tower's facing
local towerLookVector = towerCFrame.LookVector 

-- make the weldCircle follows the tower's direction but not looking down
local constrainedLookVector = Vector3.new(towerLookVector.X, 0, towerLookVector.Z).unit

-- move weldCircle a bit
local newWeldCirclePosition = tower.PrimaryPart.Position + (constrainedLookVector - 1.5)

-- update the weldCircle's CFrame
weldCircle.CFrame = CFrame.new(newWeldCirclePosition , newWeldCirclePosition + constrainedLookVector)
1 Like

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