Making npc lookat other npc one axis

I’m trying to make an npc look at another, but when the target npc is above the npc that should look. He looks op and I only want the looker to rotate in one axis. Please help me.

local targetPosition = Vector3.new(enemy.HumanoidRootPart.Position.X, enemy.HumanoidRootPart.Position.Y, enemy.HumanoidRootPart.Position.Z)
tower.HumanoidRootPart.CFrame = CFrame.new(tower.HumanoidRootPart.Position, targetPosition)
1 Like

I guess a simple workaround is to just have the target Y position be the NPC’s own Y position.

I.e.

local targetPosition = Vector3.new(enemy.HumanoidRootPart.Position.X, tower.HumanoidRootPart.Position.Y, enemy.HumanoidRootPart.Position.Z)

Supplementing @majdTRM

local EnemyPosition = enemy.HumanoidRootPart.Position
local targetPosition = Vector3.new(EnemyPosition.X, tower.HumanoidRootPart.Position.Y, EnemyPosition.Z)
tower.HumanoidRootPart.CFrame = CFrame.new(tower.HumanoidRootPart.Position, targetPosition)
1 Like

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