Hello everyone, I’m honestly not so sure that I’m writing this appropriately, but there was a problem with the fact that pathfinding does not work correctly near a wall, but specifically goes to the wall surface to the closest point to the player. I tried everything I could, it has nothing to do with the height coordinates or radius or height, I don’t understand how to solve this.
Code for pathfinding:
local function MoveToPlayer()
local success = pcall(function()path:ComputeAsync(bot.HumanoidRootPart.Position, observedP.Character.HumanoidRootPart.Position) end)
if success then
local waypoints = path:GetWaypoints()
local previouswaypoints = nil
local i = 2
local pos
while i < #waypoints + 1 do
wait(0.02)
local waypoint = 0
if (#waypoints >= 3) then
waypoint = waypoints[i]
local part = Instance.new("Part")
part.Shape = Enum.PartType.Ball
part.BrickColor = BrickColor.new(0,0,0)
part.Position = waypoint.Position
part.Anchored = true
part.CanCollide = false
part.Parent = workspace
bot.Humanoid:MoveTo(waypoint.Position)
--print(waypoints[#waypoints - 1].Position.Y)
while (Vector3.new(bot.HumanoidRootPart.Position.X, 0, bot.HumanoidRootPart.Position.Z) - Vector3.new(waypoint.Position.X, 0, waypoint.Position.Z)).Magnitude > 3 do
task.wait(0.01)
print("here")
end
if waypoint.Action == Enum.PathWaypointAction.Jump then
local state = bot.Humanoid:GetState()
while(state == Enum.HumanoidStateType.Flying or state == Enum.HumanoidStateType.Jumping) do
wait(0.1)
end
bot.Humanoid.Jump = true
end
else
bot.Humanoid:MoveTo(Vector3.new(observedP.Character.HumanoidRootPart.Position.X, playerPos, observedP.Character.HumanoidRootPart.Position.Z))
end
local velocityXZ = Vector3.new(observedP.Character.HumanoidRootPart.Velocity.X, 0, observedP.Character.HumanoidRootPart.Velocity.Z)
if velocityXZ.Magnitude > 0 then
pos = Vector3.new(observedP.Character.HumanoidRootPart.Position.X, 0, observedP.Character.HumanoidRootPart.Position.Z)
print(pos)
path:ComputeAsync(bot.PrimaryPart.Position - Vector3.new(0, bot.PrimaryPart.Size.Y/0.75, 0), pos)
waypoints = path:GetWaypoints()
if(waypoints) then
if (math.abs(waypoints[1].Position.Y - waypoints[#waypoints].Position.Y) > 2) then
i = 2
else
i = 3
end
end
else
i += 1
end
end
else
return false
end
end
Why I’m not sure that I’m writing this appropriately, because it’s not only in my script that this happens, my friend also has this thing, but a completely different script.
I hope I’ll get answers to this problem, thanks in advance.