#Moving Humanoid

19 messages · Page 1 of 1 (latest)

spark vessel
#

Hi, I am trying to figure out how to move a humanoid with just the Humanoid:Move method. I don't want to use MoveTo cause it is pretty clunky at times. This is what I have so far, and it is not working, the humanoid just goes in one direction. Imagine that waypoints is just a table of Vector3's

local RS = game:GetService("ReplicatedStorage")
local PathFinding = require(RS:WaitForChild("PathFinding"))
local dummy = script.Parent
local endPos = workspace:WaitForChild("EndPos")
local humanoid = dummy.Humanoid

local endPosition = endPos.Position
local pathfinding = PathFinding.new(true)
local waypoints = pathfinding:CreatePath(dummy, dummy.PrimaryPart.Position, endPosition)

if (waypoints == nil) then
    print("ok")
    waypoints = {}
end 

local index = 1
local current = dummy.PrimaryPart.Position * Vector3.new(1,0,1)
local endLoc = waypoints[index].pos * Vector3.new(1,0,1)
print(endLoc)
local direction = (endLoc - current).Unit
while index <= #waypoints do
    task.wait(.5)
    
    humanoid:Move(direction)
    if (dummy.PrimaryPart.Position - endLoc).Magnitude <= 1 then
        current = waypoints[index].pos * Vector3.new(1,0,1)
        index += 1
        endLoc = waypoints[index].pos * Vector3.new(1,0,1)
        direction = (endLoc - current).Unit
    else
        print((dummy.PrimaryPart.Position - endLoc).Magnitude)        
    end
end
dreamy oasis
#

What is "not working"?

#

Have you tried debugging it?

#

What does it output?

spark vessel
#

It shows that the magnitude is not reached which makes sense, but the problem is that it is not changing direction

dreamy oasis
#

Ok, so it's moving?

#

Just not changing direction?

spark vessel
#

yup

#

It might not be moving in the right direction as well

dreamy oasis
#

Probably because you're not recalculating the direction in the while-loop

#

And you're never incrementing the index are you?

spark vessel
#

I am though, when it reaches the correct direction, it should change

dreamy oasis
#

Oh yeah I see that now

spark vessel
#

destination*

#

Also, I appreciate you taking time out of your day to help me 😅

#

here I will make indicators of waypoints and can show you a video in a sec

dreamy oasis
#

Move everything from local current... - local direction... inside the while-loop before you call the :Move method

spark vessel
#

I think I fixed it, the task.wait(.5) was too long so it did not give the humanoid a chance to check before it already passed it