Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ContextActionService = game:GetService("ContextActionService")
- local Players = game:GetService("Players")
- -- Переменные для игрока, камеры, мыши.
- local player = Players.LocalPlayer
- local camera = workspace.CurrentCamera
- local button = script.Parent
- local Stick = script.Parent
- -- Переменные настройки управления
- -- Заданная скорость перемещения корабля.
- local PLAYER_SPEED = 70000
- -- Создаём вектор, в направлении которого будет двигаться персонаж
- -- Модель движется по собственной оси Z со скоростью PLAYER_SPEED
- local forwardForceVector = Vector3.new(0,0,-PLAYER_SPEED)
- local UserInputService = game:GetService("UserInputService")
- -- Функция движения, которую вызываем при нажатии на кнопку
- local function printMovement(input)
- print("\tPosition:",input.Position)
- print("\tMovement Delta:",input.Delta)
- end
- Stick.Position = UDim2.new(0.2,0,0.6,0)
- local Stick_X = Stick.AbsolutePosition.X+Stick.AbsoluteSize.X/2
- local Stick_Y = Stick.AbsolutePosition.Y+Stick.AbsoluteSize.Y/2
- UserInputService.InputBegan:Connect(function(input, gameProcessed)
- if input.UserInputType == Enum.UserInputType.Touch then
- if player.Character then
- if (input.Position.X < Stick_X*3 and
- input.Position.Y > Stick_Y*0.5) then
- Stick.Position = UDim2.new(0, input.Position.X-Stick.AbsoluteSize.X/2, 0, input.Position.Y-Stick.AbsoluteSize.Y/2)
- end
- end
- end
- end)
- UserInputService.InputChanged:Connect(function(input, gameProcessed)
- if input.UserInputType == Enum.UserInputType.Touch then
- if player.Character then
- if (input.Position.X < Stick.Parent.AbsoluteSize.X*0.4 and
- input.Position.Y > Stick.Parent.AbsoluteSize.Y*0.5) then
- local Stick_X_new = Stick.AbsolutePosition.X+Stick.AbsoluteSize.X/2
- local Stick_Y_new = Stick.AbsolutePosition.Y+Stick.AbsoluteSize.Y/2
- local X_change = input.Position.X - Stick_X_new
- local Y_change = input.Position.Y - Stick_Y_new
- --print(X_change, Y_change)
- local rootPart = player.Character:FindFirstChild("HumanoidRootPart")
- local newLocation = Vector3.new(X_change, rootPart.Position.Y, Y_change)
- --print("rootPart:", rootPart.Position,"\n" ,newLocation)
- rootPart.CFrame = CFrame.new(rootPart.Position, rootPart.Position+newLocation)
- rootPart.CFrame *= CFrame.Angles(0, math.rad(90), 0)
- player.Character.HumanoidRootPart.VectorForce.Force = forwardForceVector
- end
- end
- end
- end)
- UserInputService.InputEnded:Connect(function(input, gameProcessed)
- if input.UserInputType == Enum.UserInputType.Touch then
- if player.Character then
- player.Character.HumanoidRootPart.VectorForce.Force = Vector3.new(0,0,0)
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment