Help with making npc walk backwards from u

hello, im trying to make a npc walk backwards or the opposite way whenever he gets too close to u but ye it works but sometimes he does it sideways (im stupid pls helpa)

			local thingy = -(5 - (hrp.Position - ohrp.Position).Magnitude)
			print(check_distance)
			hum:MoveTo(CFrame.new(hrp.Position) * Vector3.new(thingy, 0, 0))
1 Like

you culd make script make it walk towards you but then reverse the vectorvelocity or something like vector3:inverse or was it cframe i forgot

2 Likes

I think this should always move them away from the player:

local scaler = 2
local movebackvector = (hrp.Position - ohrp.Position).Unit * scaler
hum:MoveTo(CFrame.new(hrp.Position + movebackvector))

You can change the scaler to change the direction amount.

Now i always get the Vector math confused (someone help :D) on which should be subbed first. But if that pushes them forward the movebackvector should be

local movebackvector = (ohrp.Position - hrp.Position).Unit * scaler
4 Likes