2

I'm making a dash but when I run the game it doesn't work as well as I expected, the first 2 dashes don't work well, the third one already works. and then at the end of the dash that transitions to being still or walking, your feet accelerate a lot. I disguised it by changing the dash time and velocity, but would someone here know something more?

--Servicios
local player = game:GetService("Players").LocalPlayer
local repStorage = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")
local runservice = game:GetService("RunService")
local debris = game:GetService("Debris")
local character = player.Character or player.CharacterAdded:Wait()
local loadedAnimation 


local fxFolder = repStorage.Fx
local dustFx = fxFolder.DustFx
local smokeFx = fxFolder.SmokeFx

-- Configuracion Dash
local key = Enum.KeyCode.Q -- Tecla para hacer el Dash
local velocity = 20000 -- velocidad del dash
local debounce = false
local cooldown = 0.20 -- Cooldown despues del Dash
local duration = 0.25 -- duracion del dash
local sideDash = false
local DashLeft = script:WaitForChild("DashLeft")
local DashRight = script:WaitForChild("DashRight")

--Variables para DustFX
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
--Partes donde se adjunatara el efecto
local lfoot = character:WaitForChild("LeftFoot") --LeftLowerLeg  / LeftFoot
local rfoot = character:WaitForChild("RightFoot") --RightLowerLeg / RightFoot
--Aca las Particulas del efecto
local fx1 = game.ReplicatedStorage.Dash.Fx.DusFX.Dust:Clone() --Fx.DusFX.ef:Clone()
fx1.Parent = rfoot
local fx2 = game.ReplicatedStorage.Dash.Fx.DusFX.Dust:Clone()
fx2.Parent = lfoot
fx1.Enabled  = false
fx2.Enabled  = false




local function UserInputButton (input, Keyboard)
    --si esta suando el teclado para escribir en el chat salgo
    if Keyboard == true then
        return
    end
    --si no esta suando el teclado para escribir continuo
    if input.KeyCode == key then
        Dash()      
    end
end


UIS.InputBegan:Connect(UserInputButton)


function Dash()

    if DashLeft == nil and DashRight == nil then return end

    if character and not debounce then
        debounce = true
        -- aca comienza el script del dash
        local humanoid = character.Humanoid
        local HRP = character.HumanoidRootPart

        --aca cambio el dash

        sideDash = not sideDash

        -- Cargamos la animación correspondiente

        if sideDash then
            loadedAnimation = humanoid.Animator:LoadAnimation(DashRight)
        else
            loadedAnimation = humanoid.Animator:LoadAnimation(DashLeft)
        end

        local dashDirection = nil
        local moveDirection = humanoid.MoveDirection
        local lookVector = HRP.CFrame.LookVector
        local minusVelocity = -velocity 

        --Chequeo que este en el piso y no flotando
        local isOnGround = humanoid.FloorMaterial ~= Enum.Material.Air and humanoid.FloorMaterial ~= Enum.Material.Water

        if isOnGround then          

            if moveDirection == Vector3.new(0,0,0) then -- si no se esta moviendo then
                dashDirection = HRP.Position + Vector3.new(lookVector.x, 0, lookVector.z)
            else
                dashDirection = HRP.Position + Vector3.new(moveDirection.X, 0, moveDirection.Z)
            end 

            --usando bodygiro para rotar al jugador en la direccion del dash suavemente
            local bodyGyro = Instance.new("BodyGyro")
            bodyGyro.Parent = HRP
            bodyGyro.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
            bodyGyro.D = 0-- is the dampening
            bodyGyro.P = 500000 -- es la agresividad
            bodyGyro.CFrame = CFrame.lookAt(HRP.Position, dashDirection) -- mira hacia donde esta y luego dash

            local attachment = Instance.new("Attachment")
            attachment.Parent = HRP

            local vectorForce = Instance.new("VectorForce")
            vectorForce.Parent = HRP
            --vector necesario para adjuntar a donde esta mirando el jugador
            vectorForce.Attachment0 = attachment
            --now it will move player foeward as the settings 
            vectorForce.Force = Vector3.new(0,0,minusVelocity)

            loadedAnimation:Play() -- comienzo la animacion
            humanoid.AutoRotate = true -- previene que el personaje se rote en si mismo
            DustFx(true, fx1, fx2)
            
            wait(duration)

            humanoid.AutoRotate = true
            

            vectorForce:Destroy()
            bodyGyro:Destroy()
            attachment:Destroy()

            -- Establecer la velocidad a cero
            humanoid.RootPart.Velocity = Vector3.new(0, 0, 0)
            loadedAnimation:Stop()      
            DustFx(false, fx1, fx2)
        end     
        wait(cooldown)
        debounce = false        
    end 
end


function DustFx(active, fx1, fx2)
    if active then
        fx1.Enabled  = true
        fx2.Enabled  = true
    else
        fx1.Enabled  = false
        fx2.Enabled  = false
    end
end

--Buscar Boton y hacer dash
local function getImageButton()
    local ScreenGuiBoton = player:WaitForChild("PlayerGui"):WaitForChild("ScreenGuiBotón")
    local ImageButton = ScreenGuiBoton:FindFirstChild("ImageButton") 

    if ImageButton then
        return ImageButton      
    else
        return nil 
    end
end

local TextBoton = getImageButton()
TextBoton.MouseButton1Click:Connect(Dash)

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.