I am trying to make a robot with pathfinding AI go to a part and not try to jump on top of it. Any simple way to do so?
Here’s the code for when the robot goes to a target.
local Humanoid = script.Parent.Humanoid
local Root = script.Parent:FindFirstChild("HumanoidRootPart")
local parts = workspace:GetPartBoundsInRadius(script.Parent.PrimaryPart.Position,100)-- A model in workspace with all spawns.
local Closest -- This will be set as the closest spawn to the player
local parent = script.Parent
local PlayerPosition = parent.PrimaryPart.Position
local calcpath = PathfindingService:CreatePath()
function calculate(thing)
warn(thing.Name.." is the target.")
calcpath:ComputeAsync(script.Parent.HumanoidRootPart.Position, thing.Position)
--calcpath:ComputeAsync(script.Parent.HumanoidRootPart.Position, workspace.Target.Position)
script.Parent.Target.Value = thing.Name
warn("Calculated!")
if calcpath.Status == Enum.PathStatus.Success then
local ways = calcpath:GetWaypoints()
warn("Where to go?")
for i, point in ipairs(ways) do
warn("I know where to go, can I get there?")
Humanoid:MoveTo(point.Position)
print("Go!")
local pathview = Instance.new("Part")
pathview.Name = "PathfindTrack"
pathview.Size = Vector3.new(1,0,1)
pathview.BrickColor = BrickColor.new("Electric blue")
pathview.Parent = workspace
pathview.Position = point.Position
pathview.Material = Enum.Material.Neon
pathview.Anchored = true
pathview.CanCollide = false
print("run")
if script.Parent.Wheel["small motor loop"].Playing == false then
script.Parent.Wheel["small motor loop"].Playing = true
end
if point.Action == Enum.PathWaypointAction.Jump then
calcpath = nil
end
Humanoid.MoveToFinished:Wait()
script.Parent.Wheel["small motor loop"].Playing = false
--script.Parent.HumanoidRootPart.Orientation = CFrame.lookAt(thing.Position, thing.Orientation)
end
else
error("Uh oh, I couldn't calculate a path!")
end
end
Good luck working with my spaghetti code.
Also, my robot, in terms of design, cannot jump.