Hello, I have a script that should make my character walk 5 studs in a random direction but for some reason, it walks like 50 studs.
--Objects//
local Humanoid = script.Parent
local HRP = script.Parent.Parent:FindFirstChild("HumanoidRootPart")
--Values
local WalkRange = 1
--Functions
while true do
local Pos1 = HRP.Position.Z + math.random(-5,5)
local Pos2 = HRP.Position.X + math.random(-5,5)
local PositionToWalk = Vector3.new(Pos1,0,Pos2)
Humanoid.WalkToPoint = PositionToWalk
wait(5)
end
You are essentially telling the code to have a character walk in a specified direction, and not based on where the character is, this should work:
local CurrentPos = HRP.Position -- The Current Position of the Character
local TargetPos = Vector3.new(math.random(-5,5),0, math.random(-5,5))
-- The Targetted Position to Traverse
Humanoid:MoveTo(CurrentPosition + Target) -- Adds Current Position with the Direction
-- you can just use Move or MoveTo
I think in order to be based on Direction, you subtract, not add: