im trying to make my npc walk backwards and also face the character. here’s my problem; these 2 lines work great seperately but won’t work together due to the cframe lookat being continuously updated i think.
catHRP.CFrame = lookatCF
cat_humanoid:MoveTo(catHRP.Position + direction * distToMoveBack)
i appreciate any help ty!!
code:
local DISTANCE = 15
local distToMoveBack = -2
local plrHum:Humanoid = c:FindFirstChildOfClass("Humanoid")
local hrp = c:WaitForChild("HumanoidRootPart")
local function update()
local mag = (hrp.Position - catHRP.Position).Magnitude
local direction = (hrp.Position - catHRP.Position).Unit
local angleinRads = math.atan2(direction.Z, direction.X)
if mag < DISTANCE then
local targetpos = Vector3.new(hrp.Position.X, catHRP.Position.Y, hrp.Position.Z)
local lookatCF = CFrame.lookAt(catHRP.Position, targetpos)
catHRP.CFrame = lookatCF
cat_humanoid:MoveTo(catHRP.Position + direction * distToMoveBack)
if not playing then
runAnimTrack:Play()
playing = true
end
else
runAnimTrack:Stop()
playing = false
end
end
connection = rs.Stepped:Connect(update)