Repository navigation
Expand file tree
/
Copy pathPhaseDashMechanic.LocalScript.lua
More file actions
79 lines (64 loc) · 2.01 KB
/
Copy pathPhaseDashMechanic.LocalScript.lua
File metadata and controls
79 lines (64 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
-- Phase Dash Mechanic for Mobile Players
-- Services
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
-- Variables
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local dashSpeed = 100
local dashDuration = 0.2
local dashCooldown = 2
local isDashing = false
local canDash = true
-- UI Setup
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = player:WaitForChild("PlayerGui")
local dashButton = Instance.new("TextButton")
dashButton.Size = UDim2.new(0, 100, 0, 100)
dashButton.Position = UDim2.new(0.8, 0, 0.8, 0)
dashButton.Text = "Dash"
dashButton.Parent = screenGui
-- Mobile Optimization
local function optimizeForMobile()
if UserInputService.TouchEnabled then
dashButton.Size = UDim2.new(0, 150, 0, 150)
dashButton.Position = UDim2.new(0.7, 0, 0.7, 0)
end
end
optimizeForMobile()
-- Dash Function
local function dash()
if not canDash or isDashing then return end
isDashing = true
canDash = false
local startTime = os.clock()
while os.clock() - startTime < dashDuration do
humanoid:ChangeState(Enum.HumanoidStateType.Physics)
character:SetVelocity(character:GetVelocity() + character.PrimaryPart.CFrame.LookVector * dashSpeed)
task.wait()
end
isDashing = false
-- Cooldown
task.wait(dashCooldown)
canDash = true
end
-- Button Event
local function onButtonActivated()
dash()
end
-- Connect the button event
if UserInputService.TouchEnabled then
dashButton.Activated:Connect(onButtonActivated)
else
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed and input.KeyCode == Enum.KeyCode.Space then
dash()
end
end)
end
-- Character Added Event
player.CharacterAdded:Connect(function(newCharacter)
character = newCharacter
humanoid = character:WaitForChild("Humanoid")
end)