Hasli4

RBLX. ControlShip

May 15th, 2025 (edited)
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.86 KB | None | 0 0
  1. local ContextActionService = game:GetService("ContextActionService")
  2. local Players = game:GetService("Players")
  3.  
  4. -- Переменные для игрока, камеры, мыши.
  5. local player = Players.LocalPlayer
  6. local camera = workspace.CurrentCamera
  7. local button = script.Parent
  8.  
  9. local Stick = script.Parent
  10.  
  11. -- Переменные настройки управления
  12. -- Заданная скорость перемещения корабля.
  13. local PLAYER_SPEED = 70000
  14.  
  15. -- Создаём вектор, в направлении которого будет двигаться персонаж
  16. -- Модель движется по собственной оси Z со скоростью PLAYER_SPEED
  17. local forwardForceVector = Vector3.new(0,0,-PLAYER_SPEED)
  18.  
  19. local UserInputService = game:GetService("UserInputService")
  20.  
  21. -- Функция движения, которую вызываем при нажатии на кнопку
  22. local function printMovement(input)
  23.     print("\tPosition:",input.Position)
  24.     print("\tMovement Delta:",input.Delta)
  25. end
  26.  
  27. Stick.Position = UDim2.new(0.2,0,0.6,0)
  28. local Stick_X = Stick.AbsolutePosition.X+Stick.AbsoluteSize.X/2
  29. local Stick_Y = Stick.AbsolutePosition.Y+Stick.AbsoluteSize.Y/2
  30.  
  31. UserInputService.InputBegan:Connect(function(input, gameProcessed)
  32.     if input.UserInputType == Enum.UserInputType.Touch then
  33.         if player.Character then
  34.             if (input.Position.X < Stick_X*3 and
  35.                 input.Position.Y > Stick_Y*0.5) then
  36.                 Stick.Position = UDim2.new(0, input.Position.X-Stick.AbsoluteSize.X/2, 0, input.Position.Y-Stick.AbsoluteSize.Y/2)
  37.             end        
  38.         end
  39.     end
  40. end)
  41.  
  42. UserInputService.InputChanged:Connect(function(input, gameProcessed)
  43.     if input.UserInputType == Enum.UserInputType.Touch then
  44.         if player.Character then
  45.             if (input.Position.X < Stick.Parent.AbsoluteSize.X*0.4 and
  46.                 input.Position.Y > Stick.Parent.AbsoluteSize.Y*0.5) then
  47.                 local Stick_X_new = Stick.AbsolutePosition.X+Stick.AbsoluteSize.X/2
  48.                 local Stick_Y_new = Stick.AbsolutePosition.Y+Stick.AbsoluteSize.Y/2
  49.                 local X_change = input.Position.X - Stick_X_new
  50.                 local Y_change = input.Position.Y - Stick_Y_new
  51.                 --print(X_change, Y_change)
  52.                 local rootPart = player.Character:FindFirstChild("HumanoidRootPart")
  53.                 local newLocation = Vector3.new(X_change, rootPart.Position.Y, Y_change)
  54.                 --print("rootPart:", rootPart.Position,"\n" ,newLocation)
  55.                 rootPart.CFrame = CFrame.new(rootPart.Position, rootPart.Position+newLocation)
  56.                 rootPart.CFrame *= CFrame.Angles(0, math.rad(90), 0)
  57.                 player.Character.HumanoidRootPart.VectorForce.Force = forwardForceVector
  58.             end
  59.         end
  60.     end
  61. end)
  62.  
  63. UserInputService.InputEnded:Connect(function(input, gameProcessed)
  64.     if input.UserInputType == Enum.UserInputType.Touch then
  65.         if player.Character then
  66.             player.Character.HumanoidRootPart.VectorForce.Force = Vector3.new(0,0,0)
  67.         end
  68.     end
  69. end)
  70.  
  71.  
Advertisement
Add Comment
Please, Sign In to add comment