Basically I've created a NPC follow script. I want to the NPC to move to any position within 3 studs away. I saw this before but I can't remember what it was.
My line:
Humanoid:MoveTo(Position*Vector3.new(0,0,3)*Units)
My goal is to move the NPC anywhere 3 studs away from that position. I believe it had something to do with units but I can't remember.
Someone please refresh my memory.
Also explain how it works that would help alot.
PS: No one in the discord would help me :c
local randomPosition = Vector3.new(math.random(-200, 200), math.random(-200, 200), math.random(-200, 200)); local normilizedRandomPosition = randomPosition/(math.abs(randomPosition.x) + math.abs(randomPosition.y) + math.abs(randomPosition.z)); Humanoid:MoveTo(Position + normilizedRandomPosition * 3);
This will move it three studs in any direction relative to its current position.
EDIT: Fixed code
EDIT: Explanation: The first line calculates a random distance. The second line takes that distance and normilizes it so that the absolute value of x, y, and z will add up to a total on one. The third line moves the humanoid to it's current position plus the position that was just normilzed multiplied by three; the outcome being that the model is moved three studs in any direction.