local character = game.Players.LocalPlayer.Character local humanoid =…
- User
local character = game.Players.LocalPlayer.Character local humanoid = character:WaitForChild("Humanoid") local PathfindingService = game:GetService("PathfindingService") local Players = game:GetService("Players") local player = Players.LocalPlayer local mouse = player:GetMouse() humanoid:MoveTo(character.HumanoidRootPart.Position) -- Получаем персонажа игрока local canceled = false
local character = player.Character or player.CharacterAdded:Wait() local humanoid = character:WaitForChild("Humanoid")
-- Обработчик нажатия на правую кнопку мыши mouse.Button2Down:Connect(function() -- Определение позиции, на которую нажата правая кнопка мыши local destination = mouse.Hit.Position destination = Vector3.new(destination.X,character.HumanoidRootPart.Position.Y,destination.Z) print(destination)
code-- Создаем сервис поиска пути local path = PathfindingService:CreatePath() -- Настройка точек начала и конца пути path:ComputeAsync(character.HumanoidRootPart.Position, destination) -- Получаем путь local waypoints = path:GetWaypoints() for i, waypoint in ipairs(waypoints) do if i < #waypoints then if canceled == false then humanoid:MoveTo(waypoint.Position) humanoid.MoveToFinished:Wait() else humanoid:MoveTo(character.HumanoidRootPart.Position) humanoid.MoveToFinished:Wait() waypoints = nil end end end canceled = falseend) -- Обработчик события клика правой кнопкой мыши game:GetService("UserInputService").InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.S then canceled = true -- Остановить движение персонажа humanoid:MoveTo(character.HumanoidRootPart.Position) end end) подкорректируй мой скрипт так, чтобы персонаж останавливался и прекращал движение когда надо
- Assistant
Исправленный скрипт, чтобы персонаж останавливался и прекращал движение по необходимости:
lua