Move turret only one one axis

I am working on a turret to shoot zombies. However, I am trying to make it only move horizontally. I though that replacing Head.Position in (script.Parent.Parent.Swivel.Position, Head.Position) with Vector3.new(Head.Position.X,0,0). However, this just made it worse. Any help is much appreciated. I am currently rotate the turret by doing the following:

script.Parent.Parent.Swivel.CFrame = CFrame.new(script.Parent.Parent.Swivel.Position, Head.Position)

What it currently looks like: https://gyazo.com/ff291b43f07c01474a1515709cff5fb5

2 Likes

Youd want to cancel out the y part, and make it level with the turret

So instead of head.Position youd do

Vector3.new(Head.Position.X, swivel.Position.Y, Head.Position.Z)
1 Like

You only need the Y-axis rotation

local turret = script.Parent.Parent.Swivel
local _, angle = CFrame.lookAt(turret.CFrame.Position, Head.CFrame.Position):ToOrientation()
turret.CFrame = CFrame.new(turret.CFrame.Position) * CFrame.Angles(0, angle, 0)
1 Like