I have been trying to make an AI for a while now, however it appears that I can’t make use of humanoid:MoveTo(). First I suspected I wasn’t able to create any waypoints but I deducted that it wasn’t the case and wasn’t a factor to this bug. I thought I had used something wrong so I looked up other people’s approach at AI but none of those worked for me for some weird reason.
I have been inserting a script directly inside a dummy created by the animation editor (by ROBLOX).
I am aware that there has been posts made similarly but none of them seemed to solve this case.
Code:
--//Services\\--
local runService = game:GetService("RunService")
--//Variables\\--
local character = script.Parent
local root = character:WaitForChild('HumanoidRootPart')
local humanoid = character:WaitForChild('Humanoid')
local part = workspace.Part
local path = game:GetService("PathfindingService"):CreatePath({AgentHeight = 5, AgentRadius = 2, AgentCanJump = false})
local newPath = path:ComputeAsync(root.Position, workspace.Part.Position)
local wayPoints = path:GetWaypoints()
if path.Status == Enum.PathStatus.Success then
for _, v in pairs(wayPoints) do
local part = Instance.new("Part", workspace)
part.Anchored = true
part.Size = Vector3.new(1,1,1)
part.Position = v.Position
part.CanCollide = false
humanoid:MoveTo(v.Position)
humanoid.MoveToFinished:Wait()
if v.Action == Enum.PathWaypointAction.Jump then
humanoid.Jump = true
end
if (wayPoints[#wayPoints].Position - workspace.Part.Position).magnitude > 15 then
break
end
end
end