Turret Rotation [Lerp CFrame Rotation]

Hello. I’m trying to make a turret that rotates. [Lots of info]

Explanation
So here I’ve got a turret.
The Turret is UnAnchored
The welds go like this -

The black part is welded to the white part.
The green part is welded to the white part.
The red part is welded to the green part.

What I’m trying to accomplish here is -
The player goes and sits on the seat.
A ServerScript clones a LocalScript to the PlayerGui.

The code inside the LocalScript runs using .RenderStepped.

LocalScript Code -

track = RS.RenderStepped:connect(function()
	for i,v in pairs(TurretsFolder.Value:GetChildren()) do
		local Position = CFrame.new(v.Body.TurretBase.CFrame.p, Vector3.new(Mouse.Hit.p.X,v.Body.TurretBase.CFrame.Y, Mouse.Hit.p.Z))
		local BasePosition = CFrame.new(v.Base.Connection.CFrame.p, Vector3.new(Mouse.Hit.p.X, v.Base.Connection.CFrame.Y, Mouse.Hit.p.Z))
		local BaseLerpPosition = v.Base.Connection.CFrame:Lerp(BasePosition, 0.15)
		local LerpPosition = v.Body.TurretBase.CFrame:Lerp(Position,0.15)
		v.Base.Connection.CFrame = BaseLerpPosition
		v.Body.TurretBase.CFrame = LerpPosition
	end
end)

This code performs this -

Now the problem I have is that I want the black part to be stationary. Imagine that the turret is going to be welded onto a tank or a starship. So I need it to be stationary and unanchored.

Summary -

I want the black part in the video above to be stationary while the others rotate.
The black part needs to be STATIONARY and UNANCHORED.
The black part will be welded to another part, that will be moving. That’s why I need it to be stationary.

Thanks for the help!

I can provide more information if necessary!

2 Likes

Then weld the black part to the baseplate :cowboy_hat_face:

@IProgramForFun. It works if the baseplate is anchored, but I need it to be unanchored, as it would be moving ingame.

1 Like

local x, y, z = Mouse.hit:ToEulerXYZ()
local TurretModel = model
Local TurretPrimary = TurretModel.PrimaryPart

TurretModel:SetPrimaryPartCFrame(TurretPrimary.Position * CFrame.Angles(math.rad(TurretPrimary.Orientation.X), y, math.rad(TurretPrimary.Orientation.Z)))

That should work.

1 Like

Ok, I’ll go try that out. Thanks for the help!