Id like some feedback on my latest dash system. I made it in the past few days and im looking for constructive critisism.
–A basic explamation of my code would be that the player double taps either W,A,S, or D, and a ray is casted in an assigned direction relative to the players HumanoidRootPart. if the ray is obstructed the dash is cancelled. If the ray has no obsticals then the dash continues.
–Some inprovements ive thought of was a camera shaking cosmetic for the client but im not sure how to use the EZ Camera shaker plug-in.
–I’d like my code to be more optimized and run smoother, im also looking for some suggestions!
Client
repeat task.wait(1) until game:IsLoaded() task.wait(1)
--Services
-----------------
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local debris = game:GetService("Debris")
-----------------
--Number Values
local dTime = .25
local tap = 0
-----------------
--Localization
local char = player.Character
local hum = char.Humanoid
local HRP = char.HumanoidRootPart
---
local event = game.ReplicatedStorage.ActiveEvent
local anims = {
animFront = hum:LoadAnimation(script.Animations:WaitForChild("W")),
animRight = hum:LoadAnimation(script.Animations:WaitForChild("D")),
animLeft = hum:LoadAnimation(script.Animations:WaitForChild("A")),
animBack = hum:LoadAnimation(script.Animations:WaitForChild("S"))
}
-----------------
--Raycast
local params = RaycastParams.new()
params.FilterDescendantsInstances = {char}
params.FilterType = Enum.RaycastFilterType.Blacklist
print("yes")
UIS.InputBegan:Connect(function(input, chat)
if chat then return end
if input.UserInputType == Enum.UserInputType.Keyboard then
local CSModule = require(game:GetService("ReplicatedStorage").Modules.CameraShaker)
if input.KeyCode == Enum.KeyCode.A then
local directions = {
right = HRP.CFrame.RightVector,
left = -HRP.CFrame.RightVector,
back = -HRP.CFrame.LookVector,
front = HRP.CFrame.LookVector
}
local origin = HRP.Position
if tick() - tap <= dTime then
print(player.Name,"has double tapped A")
local rayResult = workspace:Raycast(origin, directions.left * 23, params)
if rayResult then
print("Ray hit, dont proceed")
local hitInstance = rayResult.Instance
local hitPos = rayResult.Position
else
print("Ray wasnt hit, Proceed")
local check = event:InvokeServer({1,"DashStartUp"})
if check == "Proceed" then
hum.WalkSpeed = 0
hum.JumpHeight = 0
anims.animLeft:Play()
local check2 = event:InvokeServer({1,"DashLeft"})
if check2 == true then
hum.WalkSpeed = 16
hum.JumpHeight = 7.2
end
end
end
else
tap = tick()
end
elseif input.KeyCode == Enum.KeyCode.W then
local directions = {
right = HRP.CFrame.RightVector,
left = -HRP.CFrame.RightVector,
back = -HRP.CFrame.LookVector,
front = HRP.CFrame.LookVector
}
local origin = HRP.Position
if tick() - tap <= dTime then
print(player.Name,"has double tapped W")
local rayResult = workspace:Raycast(origin, directions.front * 23, params)
if rayResult then
print("Ray hit, dont proceed")
local hitInstance = rayResult.Instance
local hitPos = rayResult.Position
else
print("Ray wasnt hit, Proceed")
local check = event:InvokeServer({2,"DashStartUp"})
if check == "Proceed" then
hum.WalkSpeed = 0
hum.JumpHeight = 0
anims.animFront:Play()
local check2 = event:InvokeServer({2,"DashFront"})
if check2 == true then
hum.WalkSpeed = 16
hum.JumpHeight = 7.2
end
end
end
else
tap = tick()
end
elseif input.KeyCode == Enum.KeyCode.S then
local directions = {
right = HRP.CFrame.RightVector,
left = -HRP.CFrame.RightVector,
back = -HRP.CFrame.LookVector,
front = HRP.CFrame.LookVector
}
local origin = HRP.Position
if tick() - tap <= dTime then
print(player.Name,"has double tapped S")
local rayResult = workspace:Raycast(origin, directions.back * 23, params)
if rayResult then
print("Ray hit, dont proceed")
local hitInstance = rayResult.Instance
local hitPos = rayResult.Position
else
print("Ray wasnt hit, Proceed")
local check = event:InvokeServer({3,"DashStartUp"})
if check == "Proceed" then
hum.WalkSpeed = 0
hum.JumpHeight = 0
anims.animBack:Play()
local check2 = event:InvokeServer({3,"DashBack"})
if check2 == true then
hum.WalkSpeed = 16
hum.JumpHeight = 7.2
end
end
end
else
tap = tick()
end
elseif input.KeyCode == Enum.KeyCode.D then
local directions = {
right = HRP.CFrame.RightVector,
left = -HRP.CFrame.RightVector,
back = -HRP.CFrame.LookVector,
front = HRP.CFrame.LookVector
}
local origin = HRP.Position
if tick() - tap <= dTime then
print(player.Name,"has double tapped D")
local rayResult = workspace:Raycast(origin, directions.right * 23, params)
if rayResult then
print("Ray hit, dont proceed")
local hitInstance = rayResult.Instance
local hitPos = rayResult.Position
else
print("Ray wasnt hit, Proceed")
local check = event:InvokeServer({4,"DashStartUp"})
if check == "Proceed" then
hum.WalkSpeed = 0
hum.JumpHeight = 0
anims.animRight:Play()
local check2 = event:InvokeServer({4,"DashRight"})
if check2 == true then
hum.WalkSpeed = 16
hum.JumpHeight = 7.2
end
end
end
else
tap = tick()
end
end
end
end)
heres the code result
(computer lags for a bit, dont mind that )
Thank you for listenning