-- Получаем ссылку на игрового персонажа (Humanoid) local character =…
- User
-- Получаем ссылку на игрового персонажа (Humanoid) local character = game.Players.LocalPlayer.Character local humanoid = character:WaitForChild("Humanoid")
-- Получаем ссылку на PathfindingService local pathfindingService = game:GetService("PathfindingService")
-- Переменная для хранения текущего пути local currentPath = nil
-- Создаем функцию, которая будет вызываться при клике правой кнопкой мыши local function onRightClick(mouse) -- Получаем позицию, куда было кликнуто local targetPosition = mouse
-- Если уже существует активный путь, удаляем его if currentPath then currentPath = nil end -- Создаем новый путь с помощью PathfindingService currentPath = pathfindingService:CreatePath() currentPath:ComputeAsync(character.HumanoidRootPart.Position, targetPosition) -- Запускаем цикл, который будет обновлять позицию персонажа каждую секунду coroutine.wrap(function() while currentPath and currentPath.Status ~= Enum.PathStatus.Success do print(1111) -- Проверяем, есть ли путь и вычислены ли уже точки пути if currentPath.Status == Enum.PathStatus.NoPath or currentPath.Status == Enum.PathStatus.ClosestNoPath then print(959559) break end -- Получаем следующую точку пути local waypoints = currentPath:GetWaypoints() if #waypoints == 0 then break end local nextWaypoint = waypoints[1] -- Перемещаем персонажа к следующей точке пути local direction = (nextWaypoint.Position - character.HumanoidRootPart.Position).unit humanoid:MoveTo(character.HumanoidRootPart.Position + direction) wait(1) -- Подождать 1 секунду (можно изменить интервал обновления) end end)()end
-- Обработчик события клика правой кнопкой мыши game:GetService("UserInputService").InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton2 then local mouse = game.Players.LocalPlayer:GetMouse() onRightClick(mouse.Hit.Position) elseif input.KeyCode == Enum.KeyCode.S then -- Остановить движение персонажа humanoid:MoveTo(character.HumanoidRootPart.Position) end end). Я сделал все как ты сказал мне, но почему-то персонаж не идет
- Assistant
Проверьте, есть ли у персонажа компонент HumanoidRootPart. Если его нет, попробуйте заменить "character.HumanoidRootPart.Position" на "character.PrimaryPart.Position" в строке кода:
local direction = (nextWaypoint.Position - character.HumanoidRootPart.Position).unitЕсли это не помогло, убедитесь, что в вашей игре включено перемещение персонажа через клик правой кнопкой мыши.