Help with CFrame.lookAt

g’day, apologies if this is the wrong category or something

in short, i want a humanoid to look in the direction of a target, and disregard the height of the target, so, for example, if the target is 5 studs above the humanoid, i want the humanoid to look in the direction of the target, but face straight ahead, instead of facing upwards towards the target, if that makes any sense

there may be some extremely simple and easy solution i didn’t think of, but i’m bad with cframes (perhaps i don’t even need cframes or cframe.lookat).
here’s my code currently, if it helps.

local targetCFrame = CFrame.lookAt(hrp.Position, target.HumanoidRootPart.Position)
hrp.CFrame = targetCFrame

if i didn’t get my point across well, have some images to (maybe) better understand what i’m trying to do


thanks in advance

Change y component to the hrp Y component

local targetPos = Vector3.new(target.HumanoidRootPart.Position.X, hrp.Position.Y, target.HumanoidRootPart.Position.Z)

local targetCFrame = CFrame.lookAt(hrp.Position, targetPos)
hrp.CFrame = targetCFrame
3 Likes