Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a part look at a position but in a certain axis only?

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?

1 comment

0

no thats not the answer

2 answers

✓ Accepted answer
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.

1 comment

0

why not simply get the orientation.. you have the part..

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.