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.
local Humanoid = script.Parent
local HRP = script.Parent.Parent:FindFirstChild("HumanoidRootPart")
local WalkRange = 1
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
Any help is appreciated.
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:
Humanoid:MoveTo(CurrentPosition - Target) -- Direction?
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.