Rotate only the Y of AlignOrientation

Im still kinda learning about CFrame and im trying to make my Unit face the target, but because the target is big and my unit is small the unit rotates on other axis and it faces up, so i need help on how to only rotate the Y axis and doesnt make my unit faces upward

model.PrimaryPart.AlignOrientation.CFrame = CFrame.new(model.PrimaryPart.Position, target.PrimaryPart.Position)

(model is the Unit)

local guardPos: Vector3 = model.PrimaryPart.Position
local targetPos: Vector3 = target.PrimaryPart.Position

alignOrientation.CFrame = CFrame.lookAt(
    guardPos,
    Vector3.new(targetPos.X, guardPos.Y, targetPos.Z)
)

A simple replacement of Y position of the target should do the job.

Note that I used CFrame.lookAt instead of CFrame.new. Both will work the same way in this case but the overload of the CFrame constructor taking 2 Vector3s has been deprecated, and replaced with a newer method – CFrame.lookAt.

the code worked perfectly thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.