Negative/Opposite LookVector

Im trying to make an NPC look away from the target. So far I tried using

local TCF = target:GetPrimaryPartCFrame()
local NCF = NPC:GetPrimaryPartCFrame()
local newCF = TCF:ToObjectSpace(NCF)

NPC:SetPrimaryPartCFrame(CFrame.new(NCF.Position, -TCF.Position))

Doesnt work! I tried adding

local TCF = target:GetPrimaryPartCFrame()
local NCF = NPC:GetPrimaryPartCFrame()
local newCF = CFrame.new(NCF.Position, TCF.Position)
newCF = newCF * CFrame.Angles(math.rad(180), math.rad(180), math.rad(180))

Doesnt work either!

Does anyone know how I would do this?

2 Likes
NPC:SetPrimaryPartCFrame(CFrame.new(NCF.Position), -TCF.Position)

Do you mean:

NPC:SetPrimaryPartCFrame(CFrame.new(NCF.Position, -TCF.Position)) -- Notice the position of the parameters
3 Likes

Yes, You’re right! I wrote that wrong! My bad!

Try this:

local facingDirection = (TCF.Position - NCF.Position).Unit
NCP:SetPrimaryPartCFrame(CFrame.new(NCF.Position, NCF.Position - facingDirection))

Have you tried:

NPC:SetPrimaryPartCFrame(CFrame.new(NCF.Position, 2 * NCF.Position - TCF.Position))
CFrame.new(NFC.Position, Vector3.new(-TFC.Position.X,NFC.Position.Y,NFC.Position.Z))

Not surre if it works

One way this can be approached is by using the CFrame Constructor CFrame.new(Vector3 pos, Vector3 lookkAt). You can supply lookAt with the NPC’s Position - the Vector distance between the player and the NPC. Using the variables supplied, you could try NPC:SetPrimaryPartCFrame(CFrame.new(NCF.Position,NCF.Position-(TCF.Position-NCF.Position))) to achieve the desired effect.