Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

local pathfindingService = game:GetService("PathfindingService") local player =…

  1. User

    local pathfindingService = game:GetService("PathfindingService") local player = game.Players.LocalPlayer

    local waypoints = {} -- текущая цель игрока local moving = false -- флаг, определяющий, движется ли игрок в данный момент

    local function moveToWaypoint(point) if not point then return end

    local humanoidRootPart = player.Character and player.Character:FindFirstChild("HumanoidRootPart")
    
    if not humanoidRootPart then 
    	return 
    end
    
    local path = pathfindingService:CreatePath()
    path:ComputeAsync(humanoidRootPart.Position, point)
    
    if path.Status == Enum.PathStatus.Success then
    	print(11)
    	waypoints = path:GetWaypoints()
    
    	for i, waypoint in ipairs(waypoints) do
    		if waypoints then
    			humanoidRootPart.Parent.Humanoid:MoveTo(waypoint.Position) -- перемещаемся к каждой точке путиx
    			player.Character.Humanoid.MoveToFinished:Wait()
    		else
    			waypoint = nil
    			player.Character.Humanoid:MoveTo(player.Character.HumanoidRootPart.Position)
    			player.Character.Humanoid.MoveToFinished:Wait()
    		end
    	end
    
    	-- добрались до последней точки пути
    	point = nil
    else
    	-- не удалось найти путь, двигаемся к цели напрямую
    	humanoidRootPart.Parent.Humanoid:MoveTo(point)
    
    	if point and humanoidRootPart.Parent.Humanoid.WalkSpeed ~= 0 then
    		if point then
    			humanoidRootPart.Parent.Humanoid:MoveTo(point)
    		end
    	end
    
    	-- добрались до цели или была нажата кнопка “S” для прекращения движения
    	point = nil
    end
    
    moving = false -- закончили движение
    

    end

    coroutine.wrap(function() local mouse = game.Players.LocalPlayer:GetMouse()

    mouse.Button2Down:Connect(function()
    	player.Character.Humanoid:MoveTo(player.Character.HumanoidRootPart.Position)
    	player.Character.Humanoid.MoveToFinished:Wait()
    	if not moving then
    		local waypoint = mouse.Hit.Position
    
    		-- создаем коробку в целевой точке для поиска пути
    		moving = true
    		moveToWaypoint(waypoint)
    	end
    end)
    
    game:GetService("UserInputService").InputBegan:Connect(function(input)
    	if input.KeyCode == Enum.KeyCode.S then
    		player.Character.Humanoid:MoveTo(player.Character.HumanoidRootPart.Position)
    		player.Character.Humanoid.MoveToFinished:Wait()
    		waypoints = {}
    	end
    end)
    

    end)() сделай так чтобы точки пути игрока пропадали и игрок останавливался когда нажимает на клавишу S или когда выбрал дуругю точку пути.

  2. Assistant

    local pathfindingService = game:GetService("PathfindingService") local player = game.Players.LocalPlayer

    local waypoints = {} -- текущая цель игрока local moving = false -- флаг, определяющий, движется ли игрок в данный момент

    local function moveToWaypoint(point) if not point then return end

    local humanoidRootPart = player.Character and player.Character:FindFirstChild("HumanoidRootPart")
    
    if not humanoidRootPart then 
    	return 
    end
    
    local path = pathfindingService:CreatePath()
    path:ComputeAsync(humanoidRootPart.Position, point)
    
    if path.Status == Enum.PathStatus.Success then
    	waypoints = path:GetWaypoints()
    
    	for i, waypoint in ipairs(waypoints) do
    		if waypoints then
    			humanoidRootPart.Parent.Humanoid:MoveTo(waypoint.Position) -- перемещаемся к каждой точке пути
    			player.Character.Humanoid.MoveToFinished:Wait()
    			if #waypoints > i then 
    				waypoints = {} -- очищаем список точек пути, если выбрана другая цель
    				break 
    			end
    		else
    			waypoint = nil
    			player.Character.Humanoid:MoveTo(player.Character.HumanoidRootPart.Position)
    			player.Character.Humanoid.MoveToFinished:Wait()
    		end
    	end
    
    	waypoints = {} -- добрались до последней точки пути
    else
    	-- не удалось найти путь, двигаемся к цели напрямую
    	humanoidRootPart.Parent.Humanoid:MoveTo(point)
    
    	if point and humanoidRootPart.Parent.Humanoid.WalkSpeed ~= 0 then
    		if point then
    			humanoidRootPart.Parent.Humanoid:MoveTo(point)
    		end
    	end
    
    	waypoints = {} -- добрались до цели или была нажата кнопка “S” для прекращения движения
    end
    
    moving = false -- закончили движение
    

    end

    coroutine.wrap(function() local mouse = game.Players.LocalPlayer:GetMouse()

    mouse.Button2Down:Connect(function()
    	player.Character.Humanoid:MoveTo(player.Character.HumanoidRootPart.Position)
    	player.Character.Humanoid.MoveToFinished:Wait()
    	if not moving then
    		local waypoint = mouse.Hit.Position
    
    		-- создаем коробку в целевой точке для поиска пути
    		moving = true
    		moveToWaypoint(waypoint)
    	end
    end)
    
    game:GetService("UserInputService").InputBegan:Connect(function(input)
    	if input.KeyCode == Enum.KeyCode.S then
    		player.Character.Humanoid:MoveTo(player.Character.HumanoidRootPart.Position)
    		player.Character.Humanoid.MoveToFinished:Wait()
    		waypoints = {} -- очищаем список точек пути
    	end
    end)
    

    end)()