As you already know, you can use CFrame.new(position, position) to make a part look at something.
But it affects on all 3 x,y,z axis. And I only want a certain axis to be changed or stayed, for example I only want the y axis to be changed, means the part can only look around and not looking up or down. So how do you do that?
local AngleX, AngleY, AngleZ = Part.CFrame:toEulerAnglesXYZ() local LookAt = Vector3.new(AngleX, 0, AngleY) Part.CFrame = CFrame.new(Position, LookAt)
Simply replace the 0
in the definitiion of LookAt
.
You can multiply the CFrame you have to only work for one axis, like so:
Part.CFrame = CFrame.new(Pos,LookAt) * CFrame.new(1,0,0)
X-Axis
Part.CFrame = CFrame.new(Pos,LookAt) * CFrame.new(0,1,0)
Y-Axis
Part.CFrame = CFrame.new(Pos,LookAt) * CFrame.new(0,0,1)
Z-Axis
you can also use that to make it work for just two axis, i think you'll understand how.