Zyrenscripter

Mov tela

May 22nd, 2026
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.71 KB | None | 0 0
  1. -- MobileJoystick LocalScript v3
  2. -- StarterPlayerScripts
  3.  
  4. local Players = game:GetService("Players")
  5. local UserInputService = game:GetService("UserInputService")
  6. local RunService = game:GetService("RunService")
  7. local GuiService = game:GetService("GuiService")
  8.  
  9. local player = Players.LocalPlayer
  10. local character = player.Character or player.CharacterAdded:Wait()
  11. local humanoid = character:WaitForChild("Humanoid")
  12. local rootPart = character:WaitForChild("HumanoidRootPart")
  13. local camera = workspace.CurrentCamera
  14.  
  15. -- ── Velocidad ──
  16. local FINAL_SPEED = math.floor(16 * 1.06)
  17. local TP_SPEED = math.floor(FINAL_SPEED * 1.30) -- +10% siempre activo
  18. humanoid.WalkSpeed = TP_SPEED
  19.  
  20. if not UserInputService.TouchEnabled then return end
  21.  
  22. -- ── Deshabilitar joystick nativo ──
  23. local ok, PlayerModule = pcall(require, player.PlayerScripts:WaitForChild("PlayerModule"))
  24. if ok and PlayerModule then
  25. PlayerModule:GetControls():Disable()
  26. end
  27.  
  28. -- ════════════════════════════════
  29. -- GUI
  30. -- ════════════════════════════════
  31. local gui = Instance.new("ScreenGui")
  32. gui.Name = "FFJoystick"
  33. gui.ResetOnSpawn = false
  34. gui.IgnoreGuiInset = true
  35. gui.Parent = player.PlayerGui
  36.  
  37. -- Zona táctil izquierda (tamaño original)
  38. local zone = Instance.new("TextButton")
  39. zone.Size = UDim2.new(0.5, 0, 0.6, 0)
  40. zone.Position = UDim2.new(0, 0, 0.4, 0)
  41. zone.BackgroundTransparency = 1
  42. zone.Text = ""
  43. zone.Parent = gui
  44.  
  45. -- Base (oculta)
  46. local base = Instance.new("Frame")
  47. base.Size = UDim2.new(0, 140, 0, 140)
  48. base.AnchorPoint = Vector2.new(0.5, 0.5)
  49. base.BackgroundColor3 = Color3.fromRGB(10, 10, 10)
  50. base.BackgroundTransparency = 0.45
  51. base.BorderSizePixel = 0
  52. base.Visible = false
  53. base.Parent = gui
  54. Instance.new("UICorner", base).CornerRadius = UDim.new(1, 0)
  55. local s1 = Instance.new("UIStroke", base)
  56. s1.Color = Color3.fromRGB(180, 180, 180); s1.Thickness = 1.5; s1.Transparency = 0.5
  57.  
  58. -- Letras WASD
  59. for _, d in ipairs({
  60. {t="W", x=0.5, y=0.10},
  61. {t="A", x=0.10,y=0.5 },
  62. {t="S", x=0.5, y=0.87},
  63. {t="D", x=0.87,y=0.5 },
  64. }) do
  65. local l = Instance.new("TextLabel")
  66. l.Size = UDim2.new(0,20,0,20)
  67. l.AnchorPoint = Vector2.new(0.5,0.5)
  68. l.Position = UDim2.new(d.x,0,d.y,0)
  69. l.BackgroundTransparency = 1
  70. l.Text = d.t
  71. l.TextColor3 = Color3.fromRGB(200, 200, 200)
  72. l.TextScaled = true
  73. l.Font = Enum.Font.GothamBold
  74. l.Parent = base
  75. end
  76.  
  77. -- Thumb
  78. local thumb = Instance.new("Frame")
  79. thumb.Size = UDim2.new(0,52,0,52)
  80. thumb.AnchorPoint = Vector2.new(0.5,0.5)
  81. thumb.Position = UDim2.new(0.5,0,0.5,0)
  82. thumb.BackgroundColor3 = Color3.fromRGB(35, 35, 35)
  83. thumb.BackgroundTransparency = 0.3
  84. thumb.BorderSizePixel = 0
  85. thumb.Parent = base
  86. Instance.new("UICorner", thumb).CornerRadius = UDim.new(1, 0)
  87. local s2 = Instance.new("UIStroke", thumb)
  88. s2.Color = Color3.fromRGB(220,220,220); s2.Thickness = 1.5; s2.Transparency = 0.5
  89.  
  90. -- Botón de salto
  91. local jumpBtn = Instance.new("TextButton")
  92. jumpBtn.Size = UDim2.new(0,80,0,80)
  93. jumpBtn.AnchorPoint = Vector2.new(1,1)
  94. jumpBtn.Position = UDim2.new(1,-20,1,-30)
  95. jumpBtn.BackgroundColor3 = Color3.fromRGB(230,230,230)
  96. jumpBtn.BackgroundTransparency = 0.1
  97. jumpBtn.BorderSizePixel = 0
  98. jumpBtn.Text = "JUMP"
  99. jumpBtn.TextColor3 = Color3.fromRGB(40,40,40)
  100. jumpBtn.TextScaled = true
  101. jumpBtn.Font = Enum.Font.GothamBold
  102. jumpBtn.Parent = gui
  103. Instance.new("UICorner", jumpBtn).CornerRadius = UDim.new(1,0)
  104.  
  105. jumpBtn.MouseButton1Down:Connect(function()
  106. if humanoid then humanoid.Jump = true end
  107. end)
  108.  
  109.  
  110.  
  111. -- ════════════════════════════════
  112. -- ESTADO DEL JOYSTICK
  113. -- ════════════════════════════════
  114. local active = false
  115. local activeInput = nil
  116. local MAX_R = 55 -- radio máximo del thumb en px
  117. local DEAD = 14 -- dead zone en px
  118.  
  119. -- W A S D como booleanos (se activan por zona del joystick)
  120. local keys = {w=false, a=false, s=false, d=false}
  121.  
  122. local baseCenter = Vector2.new(0, 0) -- se fija al tocar
  123.  
  124. local function updateKeys(touchPos)
  125. local delta = touchPos - baseCenter
  126. local dist = delta.Magnitude
  127.  
  128. -- Mover thumb visualmente
  129. local clamped = math.min(dist, MAX_R)
  130. local dir = dist > 1 and delta.Unit or Vector2.new(0,0)
  131. thumb.Position = UDim2.new(0.5, dir.X * clamped, 0.5, dir.Y * clamped)
  132.  
  133. -- Calcular qué teclas están "presionadas"
  134. -- Dividir en zonas: arriba(W), abajo(S), izquierda(A), derecha(D)
  135. -- Con umbral angular de 67.5° por tecla (permite diagonales)
  136. if dist < DEAD then
  137. keys.w=false; keys.a=false; keys.s=false; keys.d=false
  138. return
  139. end
  140.  
  141. local angle = math.deg(math.atan2(delta.Y, delta.X))
  142. -- atan2: derecha=0, abajo=90, izquierda=180, arriba=-90
  143.  
  144. keys.w = false; keys.a = false; keys.s = false; keys.d = false
  145.  
  146. -- W+A y W+D se combinan (diagonales adelante)
  147. -- S, A solo, D solo son puros
  148. if angle > -22.5 and angle <= 22.5 then keys.d = true -- D puro
  149. elseif angle > 22.5 and angle <= 157.5 then keys.s = true -- S puro
  150. elseif angle > 157.5 or angle <= -157.5 then keys.a = true -- A puro
  151. elseif angle > -157.5 and angle <= -112.5 then keys.w=true; keys.a=true -- W+A diagonal
  152. elseif angle > -112.5 and angle <= -67.5 then keys.w = true -- W puro
  153. elseif angle > -67.5 and angle <= -22.5 then keys.w=true; keys.d=true -- W+D diagonal
  154. end
  155. end
  156.  
  157. local function resetKeys()
  158. keys.w=false; keys.a=false; keys.s=false; keys.d=false
  159. thumb.Position = UDim2.new(0.5,0,0.5,0)
  160. base.Visible = false
  161. active = false
  162. activeInput = nil
  163. end
  164.  
  165. zone.InputBegan:Connect(function(input)
  166. if input.UserInputType == Enum.UserInputType.Touch and not active then
  167. active = true
  168. activeInput = input
  169. -- input.Position está en coords de pantalla SIN el inset del GUI.
  170. -- Como IgnoreGuiInset=true el GUI sí usa coords absolutas,
  171. -- hay que sumarle el inset para que el Frame aparezca exactamente
  172. -- donde tocó el dedo (fix: joystick ya no aparece más arriba).
  173. local px = input.Position.X
  174. local py = input.Position.Y
  175. local inset = GuiService:GetGuiInset()
  176. baseCenter = Vector2.new(px, py) -- raw, para calcular delta del thumb
  177. base.Position = UDim2.fromOffset(px, py + inset.Y) -- coords absolutas GUI
  178. base.Visible = true
  179. updateKeys(Vector2.new(px, py))
  180. end
  181. end)
  182.  
  183. UserInputService.TouchMoved:Connect(function(input)
  184. if active and input == activeInput then
  185. updateKeys(Vector2.new(input.Position.X, input.Position.Y))
  186. end
  187. end)
  188.  
  189. UserInputService.TouchEnded:Connect(function(input)
  190. if active and input == activeInput then
  191. resetKeys()
  192. end
  193. end)
  194.  
  195. -- ════════════════════════════════
  196. -- MOVIMIENTO (igual que PC)
  197. -- ════════════════════════════════
  198. -- En PC, Roblox suma los vectores de cada tecla presionada:
  199. -- W → camCFrame.LookVector (plano XZ)
  200. -- S → -camCFrame.LookVector
  201. -- A → -camCFrame.RightVector
  202. -- D → camCFrame.RightVector
  203. -- Luego normaliza si magnitude > 0
  204. -- Eso es exactamente lo que hacemos aquí.
  205.  
  206. local lockedDir = nil
  207. local wasInAir = false
  208.  
  209. RunService.Heartbeat:Connect(function(dt)
  210. if not character or not character.Parent then return end
  211.  
  212. local cf = camera.CFrame
  213. local fwd = Vector3.new(cf.LookVector.X, 0, cf.LookVector.Z).Unit
  214. local right = Vector3.new(cf.RightVector.X, 0, cf.RightVector.Z).Unit
  215.  
  216. local moveDir = Vector3.new(0,0,0)
  217. if keys.w then moveDir = moveDir + fwd end
  218. if keys.s then moveDir = moveDir - fwd end
  219. if keys.d then moveDir = moveDir + right end
  220. if keys.a then moveDir = moveDir - right end
  221. if moveDir.Magnitude > 0 then
  222. moveDir = moveDir.Unit
  223. end
  224.  
  225. local isInAir = humanoid.FloorMaterial == Enum.Material.Air
  226.  
  227. -- Rotar personaje instantáneamente hacia la dirección (solo en el suelo)
  228. if moveDir.Magnitude > 0 and not isInAir then
  229. rootPart.CFrame = CFrame.new(rootPart.Position, rootPart.Position + moveDir)
  230. end
  231.  
  232. if isInAir then
  233. if not wasInAir then
  234. -- Bloquear dirección al saltar
  235. lockedDir = moveDir.Magnitude > 0 and moveDir
  236. or (rootPart.CFrame.LookVector * Vector3.new(1,0,1)).Unit
  237. end
  238. if lockedDir then
  239. humanoid:Move(lockedDir, false)
  240. end
  241. else
  242. lockedDir = nil
  243. humanoid:Move(moveDir, false)
  244. end
  245.  
  246. wasInAir = isInAir
  247. end)
  248.  
  249. -- ════════════════════════════════
  250. -- RESPAWN
  251. -- ════════════════════════════════
  252. player.CharacterAdded:Connect(function(newChar)
  253. character = newChar
  254. humanoid = newChar:WaitForChild("Humanoid")
  255. rootPart = newChar:WaitForChild("HumanoidRootPart")
  256.  
  257. -- Roblox reactiva el joystick nativo en cada respawn, hay que deshabilitarlo otra vez
  258. local okR, PM = pcall(require, player.PlayerScripts:WaitForChild("PlayerModule"))
  259. if okR and PM then
  260. PM:GetControls():Disable()
  261. end
  262.  
  263. -- Esperar un frame: el Humanoid puede resetear WalkSpeed justo después de aparecer
  264. RunService.Heartbeat:Wait()
  265. humanoid.WalkSpeed = TP_SPEED
  266.  
  267. resetKeys()
  268. wasInAir = false
  269. lockedDir = nil
  270. end)
  271.  
Advertisement
Add Comment
Please, Sign In to add comment