I have a pathfinding ship with a humanoid that needs to be able to go around planets,suns, and other ships. but I noticed that while they do avoid basic barriers. they wont go around other humanoids but will try to go straight through. this is a problem for two main reasons.
1: the planets are humanoids themselves, so a ship will try to go through it rather than around.
2: the planets are also colonizable, so when a ship comes into contact with the planet it may unintentionally land in it.
here is my pathfinding script:
local PathfindingService = game:GetService("PathfindingService")
local ship = script.Parent.Parent.Parent
local humanoid = ship.Humanoid
local goal = script.Parent
local path = PathfindingService:CreatePath()
local waypoints
local currentWaypointIndex
local showpoints = false --if true shows the waypoints.
local waypointcontainer = Instance.new("Model")
local cleanpoints = false
function FollowPath(goal)
path:ComputeAsync(ship.HumanoidRootPart.Position, goal.Value)
waypoints = {}
if path.Status == Enum.PathStatus.Success then
waypoints = path:GetWaypoints()
currentWaypointIndex = 1
humanoid:MoveTo(waypoints[currentWaypointIndex].Position)
else
humanoid:MoveTo(ship.HumanoidRootPart.Position)
cleanpoints = true
end
end
function onWaypointReached(reached)
if reached and currentWaypointIndex < #waypoints then
currentWaypointIndex = currentWaypointIndex + 1
humanoid:MoveTo(waypoints[currentWaypointIndex].Position)
elseif reached and waypointcontainer and currentWaypointIndex == #waypoints then
cleanpoints = true
end
end
function showwaypoints()
spawn(function()
waypointcontainer.Parent = game.Workspace
local waypoints = path:GetWaypoints()
for _, waypoint in pairs(waypoints) do
local part = Instance.new("Part")
part.Shape = "Ball"
part.Material = "Neon"
part.Size = Vector3.new(0.6, 0.6, 0.6)
part.Position = waypoint.Position
part.Anchored = true
part.CanCollide = false
part.Parent = waypointcontainer
end
repeat
wait()
until
cleanpoints == true
if cleanpoints == true then
waypointcontainer:Destroy()
cleanpoints = false
waypointcontainer = Instance.new("Model")
end
end)
end
humanoid.MoveToFinished:Connect(onWaypointReached)
script.Parent.Changed:Connect(function()
if script.Parent.Value ~= Vector3.new(0,0,0) then
FollowPath(goal)
if showpoints == true then
showwaypoints()
end
end
end)
is there something I can do to have other humanoids be treated like any other blocked barrier?