Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

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

Asked by 6 years ago
Edited 6 years ago

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?

0
no thats not the answer Konethorix 197 — 6y

2 answers

Log in to vote
0
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago
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.

0
why not simply get the orientation.. you have the part.. User#20388 0 — 6y
Ad
Log in to vote
0
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
6 years ago

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.

Answer this question