How to make turrent move

Hello there,

I am creating a turrent on a boat and I have use the qPerfectionWeld to weld it all together via a script. I am trying to make it so wherever your mouse faces the turrent faces also. Here is my code:

while true do
	for i,v in pairs(Turrent:GetDescendants()) do
		if v:IsA("Part") then
			v.CFrame = CFrame.new(v.Position, Mouse.Hit.Position)
		end
	end
	
	task.wait()
end

However, this moves not only the turrent but the boat aswell when I only want it to move the turrent. I have looked at other topics concerning this however none of them have worked for me.

Any help is appreciated, thanks.

This is just a guess, but you could try unanchoring the turret

Are the parts in said welded boat unanchored? If so, the turret can’t be welded to the rest of the boat, otherwise it will always move the boat with it. I would recommend perhaps moving the turret completely separate. Assuming this is a localscript, I would use

local RunService=game:GetService("RunService")

RunService.RenderStepped:Connect(function()
       --set position of turret to a certain point on the boat. 
      for i, v in pairs(turret:GetDescendants()) do
            if v:IsA("BasePart") then
                  --[[Offset the cframe of the part with a designated point on the boat, lets say 
                  "turretbase" and then you can set it to the mouse position ]]--
            end
      end
end)

Here is a good tutorial about using a hinge constraint for the turret that may help you out.

Hinges won’t work if the turret is still welded though. If this method is used, the turret model would have to be separate from the welded model, but otherwise this would be a good option.

If the boat is welded together you will need to change the C0.

It is pretty complex so I made a resource for that, the resource uses Motor6Ds which also has the same properties as welds as a “Joint Instance” with also a C0 and C1 so it should work as well with a few adjustments and correct initial conditions:

1 Like

Didn’t say they would. I simply said that the tutorial used them and since it shows it from scratch it would be a good idea to watch and they would see how the turret is attached to the boat. Always good to see other examples to determine what will work best for your situation.

I agree, hence why I added that it was a good option, I simply wanted to note that it wouldn’t work with the current setup with the turret and boat weld-wise, but it’s a good method to use and a video well suited for the goal trying to be achieved. :slightly_smiling_face: