papapyst

Free cam script

Oct 6th, 2024
6,202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.66 KB | None | 0 0
  1. -- free cam mobile made by @pystYT
  2. -- kinda bad
  3.  
  4. local Players = game:GetService("Players")
  5. local UserInputService = game:GetService("UserInputService")
  6. local RunService = game:GetService("RunService")
  7. local Camera = game.Workspace.CurrentCamera
  8. local LocalPlayer = Players.LocalPlayer
  9.  
  10. -- Create the main GUI components
  11. local ScreenGui = Instance.new("ScreenGui")
  12. local FCButton = Instance.new("TextButton")
  13. local ForwardButton = Instance.new("TextButton")
  14. local BackwardButton = Instance.new("TextButton")
  15. local LeftButton = Instance.new("TextButton")
  16. local RightButton = Instance.new("TextButton")
  17.  
  18. -- Properties for the "FC" button
  19. ScreenGui.Parent = game.CoreGui
  20. FCButton.Parent = ScreenGui
  21. FCButton.Text = "FC"
  22. FCButton.Size = UDim2.new(0, 50, 0, 50) -- Size of the button
  23. FCButton.Position = UDim2.new(0.92, 0, 0.05, 0) -- Top right corner
  24. FCButton.BackgroundColor3 = Color3.fromRGB(0, 0, 255) -- Blue color
  25. FCButton.TextColor3 = Color3.fromRGB(255, 255, 255) -- White text
  26. FCButton.BorderSizePixel = 0
  27. FCButton.TextScaled = true
  28.  
  29. -- Function to configure movement buttons
  30. local function configureButton(button, text, position)
  31. button.Text = text
  32. button.Size = UDim2.new(0, 50, 0, 50)
  33. button.Position = position
  34. button.BackgroundColor3 = Color3.fromRGB(100, 100, 100)
  35. button.TextColor3 = Color3.fromRGB(255, 255, 255)
  36. button.BorderSizePixel = 0
  37. button.TextScaled = true
  38. button.Visible = false
  39. button.Parent = ScreenGui
  40. end
  41.  
  42. -- Configure movement buttons at bottom left
  43. configureButton(ForwardButton, "↑", UDim2.new(0.05, 0, 0.7, 0))
  44. configureButton(BackwardButton, "↓", UDim2.new(0.05, 0, 0.8, 0))
  45. configureButton(LeftButton, "←", UDim2.new(0.00, 0, 0.75, 0))
  46. configureButton(RightButton, "→", UDim2.new(0.1, 0, 0.75, 0))
  47.  
  48. -- Movement variables
  49. local isFreeCam = false
  50. local isShowingButtons = false
  51. local moveSpeed = 1
  52. local lookSpeed = 0.2
  53. local moveVector = Vector3.new(0, 0, 0)
  54. local lookVector = Vector2.new(0, 0)
  55.  
  56. local movementDirection = Vector3.new(0, 0, 0)
  57.  
  58. -- Toggle free camera and show/hide movement buttons
  59. local function toggleFreeCam()
  60. isFreeCam = not isFreeCam
  61. if isFreeCam then
  62. Camera.CameraType = Enum.CameraType.Scriptable
  63. ForwardButton.Visible = true
  64. BackwardButton.Visible = true
  65. LeftButton.Visible = true
  66. RightButton.Visible = true
  67. isShowingButtons = true
  68. else
  69. Camera.CameraType = Enum.CameraType.Custom
  70. ForwardButton.Visible = false
  71. BackwardButton.Visible = false
  72. LeftButton.Visible = false
  73. RightButton.Visible = false
  74. isShowingButtons = false
  75. end
  76. end
  77.  
  78. -- Button press event listeners to control movement direction
  79. ForwardButton.MouseButton1Down:Connect(function()
  80. movementDirection = Vector3.new(0, 0, -1) -- Move forward
  81. end)
  82. ForwardButton.MouseButton1Up:Connect(function()
  83. movementDirection = Vector3.new(0, 0, 0)
  84. end)
  85.  
  86. BackwardButton.MouseButton1Down:Connect(function()
  87. movementDirection = Vector3.new(0, 0, 1) -- Move backward
  88. end)
  89. BackwardButton.MouseButton1Up:Connect(function()
  90. movementDirection = Vector3.new(0, 0, 0)
  91. end)
  92.  
  93. LeftButton.MouseButton1Down:Connect(function()
  94. movementDirection = Vector3.new(-1, 0, 0) -- Move left
  95. end)
  96. LeftButton.MouseButton1Up:Connect(function()
  97. movementDirection = Vector3.new(0, 0, 0)
  98. end)
  99.  
  100. RightButton.MouseButton1Down:Connect(function()
  101. movementDirection = Vector3.new(1, 0, 0) -- Move right
  102. end)
  103. RightButton.MouseButton1Up:Connect(function()
  104. movementDirection = Vector3.new(0, 0, 0)
  105. end)
  106.  
  107. -- Screen dragging for looking around
  108. UserInputService.TouchMoved:Connect(function(input)
  109. if isFreeCam then
  110. local delta = input.Position - input.PreviousPosition
  111. lookVector = Vector2.new(-delta.X, -delta.Y) * lookSpeed
  112. end
  113. end)
  114.  
  115. -- Free cam movement logic
  116. RunService.RenderStepped:Connect(function()
  117. if isFreeCam then
  118. local forward = Camera.CFrame.LookVector
  119. local right = Camera.CFrame.RightVector
  120. local up = Camera.CFrame.UpVector
  121.  
  122. -- Move the camera in the desired direction
  123. local moveDirection = (right * movementDirection.X + forward * movementDirection.Z).unit
  124. Camera.CFrame = Camera.CFrame + moveDirection * moveSpeed
  125.  
  126. -- Look around the camera
  127. local angles = CFrame.Angles(lookVector.Y, lookVector.X, 0)
  128. Camera.CFrame = Camera.CFrame * angles
  129.  
  130. -- Reset look vector to avoid continuous spinning
  131. lookVector = Vector2.new(0, 0)
  132. end
  133. end)
  134.  
  135. -- Toggle free cam on FCButton click
  136. FCButton.MouseButton1Click:Connect(function()
  137. toggleFreeCam()
  138. end)
Advertisement
Add Comment
Please, Sign In to add comment